[logaling-commit] logaling/logaling-command [add-loga-copy] Correct behavior of copy command

Zurück zum Archiv-Index

SUZUKI Miho null+****@clear*****
Thu Aug 16 17:09:10 JST 2012


SUZUKI Miho	2012-08-16 17:09:10 +0900 (Thu, 16 Aug 2012)

  New Revision: 0d606d9f1f9a4b66d0afe37f3b3128d7432aaf53
  https://github.com/logaling/logaling-command/commit/0d606d9f1f9a4b66d0afe37f3b3128d7432aaf53

  Log:
    Correct behavior of copy command

  Modified files:
    lib/logaling/command/application.rb

  Modified: lib/logaling/command/application.rb (+12 -7)
===================================================================
--- lib/logaling/command/application.rb    2012-08-16 17:02:06 +0900 (c03cf1c)
+++ lib/logaling/command/application.rb    2012-08-16 17:09:10 +0900 (6983c9e)
@@ -360,17 +360,22 @@ module Logaling::Command
     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
+      projects =****@repos*****
+      project_candidates = projects.reject { |project| project.name != project_name }
+      project_original = project_candidates.detect do |project|
+        project.has_glossary?(source_language, target_language)
+      end
+      unless project_original
+        raise Logaling::GlossaryNotFound, "Can't found #{project_name}.#{source_language}.#{target_language}"
+      end
 
       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)
+      project_original.glossary(source_language, target_language).terms.each do |term|
+        glossary_new.add(term[:source_term], term[:target_term], term[:note])
+      end
 
-    rescue Logaling::CommandFailed, Logaling::GlossaryAlreadyRegistered => e
+    rescue Logaling::CommandFailed, Logaling::GlossaryAlreadyRegistered, Logaling::GlossaryNotFound => e
       say e.message
     end
 
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Zurück zum Archiv-Index