[logaling-commit] logaling/logaling-command [move-bilingual-pair-exists] Move #bilingual_pair_exists? to Glossary#add(#update / #delete)

Back to archive index

SUZUKI Miho null+****@clear*****
Thu Sep 20 20:30:17 JST 2012


SUZUKI Miho	2012-09-20 20:30:17 +0900 (Thu, 20 Sep 2012)

  New Revision: 192b23640c9f219a4bda161d40ef1e6f9ac25e76
  https://github.com/logaling/logaling-command/commit/192b23640c9f219a4bda161d40ef1e6f9ac25e76

  Log:
    Move #bilingual_pair_exists? to Glossary#add(#update / #delete)

  Modified files:
    lib/logaling/command/application.rb
    lib/logaling/glossary.rb
    spec/logaling/glossary_spec.rb
    spec/logaling/repository_spec.rb

  Modified: lib/logaling/command/application.rb (+6 -8)
===================================================================
--- lib/logaling/command/application.rb    2012-09-20 17:54:44 +0900 (c7fc476)
+++ lib/logaling/command/application.rb    2012-09-20 20:30:17 +0900 (74ae463)
@@ -190,13 +190,12 @@ module Logaling::Command
       raise Logaling::ProjectNotFound unless project
       raise Logaling::ProjectNotFound if project.imported?
       glossary = project.glossary(@config.source_language, @config.target_language)
-      if glossary.bilingual_pair_exists?(source_term, target_term)
-        raise Logaling::TermError, "term '#{source_term}: #{target_term}' already exists in '#{@config.glossary}'"
-      end
 
       glossary.add(source_term, target_term, note)
-    rescue Logaling::CommandFailed, Logaling::TermError => e
+    rescue Logaling::CommandFailed => e
       say e.message
+    rescue Logaling::TermError => e
+      say "term '#{source_term}: #{target_term}' already exists in '#{@config.glossary}'"
     rescue Logaling::GlossaryNotFound => e
       say "Try 'loga new or register' first."
     rescue Logaling::ProjectNotFound
@@ -244,13 +243,12 @@ module Logaling::Command
       project =****@repos*****_project(@config.glossary)
       raise Logaling::ProjectNotFound unless project
       glossary = project.glossary(@config.source_language, @config.target_language)
-      if glossary.bilingual_pair_exists?(source_term, new_target_term, note)
-        raise Logaling::TermError, "term '#{source_term}: #{new_target_term}' already exists in '#{@config.glossary}'"
-      end
 
       glossary.update(source_term, target_term, new_target_term, note)
-    rescue Logaling::CommandFailed, Logaling::TermError => e
+    rescue Logaling::CommandFailed => e
       say e.message
+    rescue Logaling::TermError => e
+      say "term '#{source_term}: #{new_target_term}' already exists in '#{@config.glossary}'"
     rescue Logaling::GlossaryNotFound => e
       say "Try 'loga new or register' first."
     rescue Logaling::ProjectNotFound

  Modified: lib/logaling/glossary.rb (+3 -0)
===================================================================
--- lib/logaling/glossary.rb    2012-09-20 17:54:44 +0900 (1b77687)
+++ lib/logaling/glossary.rb    2012-09-20 20:30:17 +0900 (dce61bc)
@@ -54,14 +54,17 @@ module Logaling
     end
 
     def add(source_term, target_term, note)
+      raise Logaling::TermError if bilingual_pair_exists?(source_term, target_term)
       glossary_source.add(source_term, target_term, note)
     end
 
     def update(source_term, target_term, new_target_term, note)
+      raise Logaling::TermError if bilingual_pair_exists?(source_term, new_target_term, note)
       glossary_source.update(source_term, target_term, new_target_term, note)
     end
 
     def delete(source_term, target_term)
+      raise Logaling::TermError unless bilingual_pair_exists?(source_term, target_term)
       glossary_source.delete(source_term, target_term)
     end
 

  Modified: spec/logaling/glossary_spec.rb (+2 -0)
===================================================================
--- spec/logaling/glossary_spec.rb    2012-09-20 17:54:44 +0900 (f24da4d)
+++ spec/logaling/glossary_spec.rb    2012-09-20 20:30:17 +0900 (a629ba9)
@@ -98,6 +98,8 @@ module Logaling
         before do
           glossary.add("delete_logaling", "てすと1", "備考")
           glossary.add("delete_logaling", "てすと2", "備考")
+          # in order to index certainly
+          sleep(1)
           glossary.delete("delete_logaling", "てすと1")
           repository.index
           @result = repository.lookup("delete_logaling", glossary)

  Modified: spec/logaling/repository_spec.rb (+2 -0)
===================================================================
--- spec/logaling/repository_spec.rb    2012-09-20 17:54:44 +0900 (4b2818f)
+++ spec/logaling/repository_spec.rb    2012-09-20 20:30:17 +0900 (5bfddc7)
@@ -118,6 +118,8 @@ module Logaling
           File.open(glossary_source_path, 'w') do |f|
             YAML.dump([], f)
           end
+          # in order to index certainly
+          sleep(1)
           glossary.add("spec_logaling", "スペック", "備考")
           repository.index
           @terms = repository.lookup("spec_logaling", glossary)
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Back to archive index