null+****@clear*****
null+****@clear*****
Tue Feb 21 13:21:04 JST 2012
SHIMADA Koji 2012-02-21 13:21:04 +0900 (Tue, 21 Feb 2012) New Revision: eacf5c5d32cfd25a2c7c2115d9ddee404583c905 Log: Move Glossary.build_path to instance method and rename - rename to Glossary#source_path Modified files: lib/logaling/glossary.rb spec/logaling/command_spec.rb spec/logaling/glossary_spec.rb spec/logaling/repository_spec.rb Modified: lib/logaling/glossary.rb (+19 -15) =================================================================== --- lib/logaling/glossary.rb 2012-02-20 12:24:58 +0900 (2bb0586) +++ lib/logaling/glossary.rb 2012-02-21 13:21:04 +0900 (2ba6fd3) @@ -60,33 +60,28 @@ module Logaling end glossary end - - def build_path(glossary, source_language, target_language, logaling_home) - fname = [glossary, source_language, target_language].join(".") - File.join(logaling_home, "projects", glossary, "glossary", "#{fname}.yml") - end end attr_reader :glossary, :source_language, :target_language def initialize(glossary, source_language, target_language, logaling_home) - @path = Glossary.build_path(glossary, source_language, target_language, logaling_home) + @logaling_home = logaling_home @glossary = glossary @source_language = source_language @target_language = target_language end def add(source_term, target_term, note) - FileUtils.touch(@path) unless File.exist?(@path) + FileUtils.touch(source_path) unless File.exist?(source_path) - glossary = Glossary.load_glossary(@path) + glossary = Glossary.load_glossary(source_path) glossary << build_term(source_term, target_term, note) dump_glossary(glossary) end def update(source_term, target_term, new_target_term, note) - raise GlossaryNotFound unless File.exist?(@path) + raise GlossaryNotFound unless File.exist?(source_path) - glossary = Glossary.load_glossary(@path) + glossary = Glossary.load_glossary(source_path) target_index = find_term_index(glossary, source_term, target_term) if target_index @@ -98,9 +93,9 @@ module Logaling end def delete(source_term, target_term) - raise GlossaryNotFound unless File.exist?(@path) + raise GlossaryNotFound unless File.exist?(source_path) - glossary = Glossary.load_glossary(@path) + glossary = Glossary.load_glossary(source_path) target_index = find_term_index(glossary, source_term, target_term) unless target_index raise TermError, "Can't found term '#{source_term} #{target_term}' in '#{@glossary}'" unless target_index @@ -111,9 +106,9 @@ module Logaling end def delete_all(source_term, force=false) - raise GlossaryNotFound unless File.exist?(@path) + raise GlossaryNotFound unless File.exist?(source_path) - glossary = Glossary.load_glossary(@path) + glossary = Glossary.load_glossary(source_path) delete_candidates = target_terms(glossary, source_term) if delete_candidates.empty? raise TermError, "Can't found term '#{source_term} in '#{@glossary}'" @@ -129,6 +124,15 @@ module Logaling end end + def source_path + if @source_path + @source_path + else + fname = [@glossary, @source_language, @target_language].join(".") + @source_path = File.join(@logaling_home, "projects", @glossary, "glossary", "#{fname}.yml") + end + end + private def build_term(source_term, target_term, note) note ||= '' @@ -158,7 +162,7 @@ module Logaling end def dump_glossary(glossary) - File.open(@path, "w") do |f| + File.open(source_path, "w") do |f| f.puts(glossary.to_yaml) end end Modified: spec/logaling/command_spec.rb (+2 -1) =================================================================== --- spec/logaling/command_spec.rb 2012-02-20 12:24:58 +0900 (98fd75d) +++ spec/logaling/command_spec.rb 2012-02-21 13:21:04 +0900 (22ee439) @@ -22,7 +22,8 @@ describe Logaling::Command::Application do let(:logaling_config) { File.join(File.dirname(__FILE__), "..", "tmp", ".logaling") } let(:base_options) { {"glossary"=>"spec", "source-language"=>"en", "target-language"=>"ja", "logaling-config" => logaling_config} } let(:command) { Logaling::Command::Application.new([], base_options) } - let(:glossary_path) { Logaling::Glossary.build_path('spec', 'en', 'ja', logaling_home) } + let(:glossary) { Logaling::Glossary.new('spec', 'en', 'ja', logaling_home) } + let(:glossary_path) { glossary.source_path } let(:target_project_path) { File.join(logaling_home, "projects", "spec") } let(:repository) { Logaling::Repository.new(logaling_home) } Modified: spec/logaling/glossary_spec.rb (+1 -1) =================================================================== --- spec/logaling/glossary_spec.rb 2012-02-20 12:24:58 +0900 (c993432) +++ spec/logaling/glossary_spec.rb 2012-02-21 13:21:04 +0900 (4b2c79c) @@ -23,7 +23,7 @@ module Logaling let(:project) { "spec" } let(:logaling_home) { @logaling_home } let(:glossary) { Glossary.new(project, 'en', 'ja', logaling_home) } - let(:glossary_path) { Glossary.build_path(project, 'en', 'ja', logaling_home) } + let(:glossary_path) { glossary.source_path } let(:repository) { Logaling::Repository.new(logaling_home) } before do Modified: spec/logaling/repository_spec.rb (+1 -1) =================================================================== --- spec/logaling/repository_spec.rb 2012-02-20 12:24:58 +0900 (45d8f64) +++ spec/logaling/repository_spec.rb 2012-02-21 13:21:04 +0900 (01a7f5a) @@ -23,7 +23,7 @@ module Logaling let(:project) { "spec" } let(:logaling_home) { @logaling_home } let(:glossary) { Glossary.new(project, 'en', 'ja', logaling_home) } - let(:glossary_path) { Glossary.build_path(project, 'en', 'ja', logaling_home) } + let(:glossary_path) { glossary.source_path } let(:repository) { Logaling::Repository.new(logaling_home) } let(:db_home) { File.join(logaling_home, "db") }