SUZUKI Miho
null+****@clear*****
Mon Aug 13 20:29:50 JST 2012
SUZUKI Miho 2012-08-13 20:29:50 +0900 (Mon, 13 Aug 2012) New Revision: ede385b990db7386156a2addc5b8728c4d2b6798 https://github.com/logaling/logaling-command/commit/ede385b990db7386156a2addc5b8728c4d2b6798 Log: Add 'loga copy' command Modified files: lib/logaling/command/application.rb spec/logaling/command_spec.rb Modified: lib/logaling/command/application.rb (+19 -1) =================================================================== --- lib/logaling/command/application.rb 2012-08-13 13:48:12 +0900 (3dc4ed6) +++ lib/logaling/command/application.rb 2012-08-13 20:29:50 +0900 (c03cf1c) @@ -54,7 +54,8 @@ module Logaling::Command '-U' => :unregister, '-L' => :list, '-s' => :show, - '-v' => :version + '-v' => :version, + '-c' => :copy class_option "glossary", type: :string, aliases: "-g" class_option "source-language", type: :string, aliases: "-S" @@ -356,6 +357,23 @@ module Logaling::Command say e.message end + desc 'copy [GLOSSARY NAME] [SOURCE LANGUAGE] [TARGET LANGUAGE] [NEW GLOSSARY NAME] [NEW SOURCE LANGUAGE] [NEW TARGET LANGUAGE]', 'Copy personal glossary' + def copy(project_name, source_language, target_language, new_project_name, new_source_language, new_target_language) + check_logaling_home_exists + project_original =****@repos*****_project(project_name) + glossary_original = project_original.glossary(source_language, target_language) + glossary_source_path_original = glossary_original.glossary_source.source_path + + project_new =****@repos*****_personal_project(new_project_name, new_source_language, new_target_language) + glossary_new = project_new.glossary(new_source_language, new_target_language) + glossary_source_path_new = glossary_new.glossary_source.source_path + + FileUtils.copy(glossary_source_path_original, glossary_source_path_new) + + rescue Logaling::CommandFailed, Logaling::GlossaryAlreadyRegistered => e + say e.message + end + private def error(msg) STDERR.puts(msg) Modified: spec/logaling/command_spec.rb (+30 -0) =================================================================== --- spec/logaling/command_spec.rb 2012-08-13 13:48:12 +0900 (4aaec17) +++ spec/logaling/command_spec.rb 2012-08-13 20:29:50 +0900 (02b0733) @@ -508,8 +508,38 @@ describe Logaling::Command::Application do end end + describe '#copy' do + let(:copied_glossary_path) { File.join(logaling_home, 'personal', 'spec.en.fr.yml') } + before do + command.new('spec', 'en', 'ja') + command.add('spec logaling', 'すぺっくろがりん') + end + + context 'when new glossary does not exist' do + before do + command.copy('spec', 'en', 'ja', 'spec', 'en', 'fr') + @yaml = YAML::load_file(copied_glossary_path).find{|h| h["source_term"] == "spec logaling" } + end + + it 'should copy from original glossary' do + @yaml.should == {"source_term"=>"spec logaling", "target_term"=>"すぺっくろがりん", "note"=>""} + end + end + + context 'when same glossary exists in glossary list' do + before do + @stdout = capture(:stdout) {command.copy('spec', 'en', 'ja', 'spec', 'en', 'ja')} + end + + it 'should not copy glossary' do + @stdout.should include "already exists" + end + end + end + after do FileUtils.rm_rf(logaling_config) FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec')) + FileUtils.rm_rf(File.join(logaling_home, 'personal')) end end -------------- next part -------------- An HTML attachment was scrubbed... Download