[logaling-commit] logaling/logaling-command [master] Use glossary object instead of glossary source when run add command

Back to archive index

null+****@clear***** null+****@clear*****
Wed Jun 13 16:28:51 JST 2012


SUZUKI Miho	2012-06-13 16:28:51 +0900 (Wed, 13 Jun 2012)

  New Revision: 32963319b0be6f2a8683ba971856c0ae90f2e4d1
  https://github.com/logaling/logaling-command/commit/32963319b0be6f2a8683ba971856c0ae90f2e4d1

  Merged 7228757: Merge pull request #60 from logaling/refactor-structure

  Log:
    Use glossary object instead of glossary source when run add command

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

  Modified: lib/logaling/command/application.rb (+4 -4)
===================================================================
--- lib/logaling/command/application.rb    2012-06-13 15:43:46 +0900 (3d5cf7c)
+++ lib/logaling/command/application.rb    2012-06-13 16:28:51 +0900 (891a3b9)
@@ -169,13 +169,13 @@ module Logaling::Command
       }
       @config.check_required_option(required_options)
       check_logaling_home_exists
-      @repository.index
-
-      if****@repos*****_pair_exists?(source_term, target_term, @config.glossary)
+      project =****@repos*****_project(@config.glossary)
+      glossary = project.find_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_source.add(source_term, target_term, note)
+      glossary.add(source_term, target_term, note)
     rescue Logaling::CommandFailed, Logaling::TermError => e
       say e.message
     rescue Logaling::GlossaryNotFound => e

  Modified: lib/logaling/glossary.rb (+25 -0)
===================================================================
--- lib/logaling/glossary.rb    2012-06-13 15:43:46 +0900 (dd3dd77)
+++ lib/logaling/glossary.rb    2012-06-13 16:28:51 +0900 (632f1af)
@@ -37,6 +37,20 @@ module Logaling
       terms
     end
 
+    def bilingual_pair_exists?(source_term, target_term)
+      raise Logaling::GlossaryDBNotFound unless File.exist?(@project.glossary_db_path)
+      index
+      terms = []
+      Logaling::GlossaryDB.open(@project.glossary_db_path, "utf8") do |db|
+        terms = db.get_bilingual_pair(source_term, target_term, @name)
+      end
+      !terms.empty?
+    end
+
+    def add(source_term, target_term, note)
+      glossary_source.add(source_term, target_term, note)
+    end
+
     private
     def index
       Logaling::GlossaryDB.open(@project.glossary_db_path, "utf8") do |db|
@@ -64,5 +78,16 @@ module Logaling
       end
       Dir.glob(glob_condition)
     end
+
+    def glossary_source
+      if @glossary_source
+        @glossary_source
+      else
+        @glossary_source = Logaling::GlossarySource.new(@name, @source_language, @target_language)
+        file_name = [@name, @source_language, @target_language, 'yml'].join('.')
+        @glossary_source.source_path = File.join(@project.glossary_source_path, file_name)
+        @glossary_source
+      end
+    end
   end
 end

  Modified: lib/logaling/glossary_source.rb (+2 -1)
===================================================================
--- lib/logaling/glossary_source.rb    2012-06-13 15:43:46 +0900 (e8fdb42)
+++ lib/logaling/glossary_source.rb    2012-06-13 16:28:51 +0900 (1bde6a5)
@@ -62,8 +62,9 @@ module Logaling
       end
     end
     attr_reader :glossary, :source_language, :target_language
+    attr_writer :source_path
 
-    def initialize(glossary_name, source_language, target_language, logaling_home)
+    def initialize(glossary_name, source_language, target_language, logaling_home = nil)
       @logaling_home = logaling_home
       @glossary = glossary_name
       @source_language = source_language
-------------- next part --------------
An HTML attachment was scrubbed...
다운로드 



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