SUZUKI Miho
null+****@clear*****
Mon Nov 5 19:53:15 JST 2012
SUZUKI Miho 2012-11-05 19:53:15 +0900 (Mon, 05 Nov 2012) New Revision: e1f8aa62ed0077365a8eaef24318b0e4593a4608 https://github.com/logaling/logaling-command/commit/e1f8aa62ed0077365a8eaef24318b0e4593a4608 Log: [#38557667] Add project object to glossary object from DB Modified files: lib/logaling/glossary.rb lib/logaling/glossary_db.rb lib/logaling/project.rb Modified: lib/logaling/glossary.rb (+1 -1) =================================================================== --- lib/logaling/glossary.rb 2012-11-05 11:47:43 +0900 (6f4f03d) +++ lib/logaling/glossary.rb 2012-11-05 19:53:15 +0900 (e6419cd) @@ -19,7 +19,7 @@ module Logaling SUPPORTED_FILE_TYPE = %w(yml tsv csv) SUPPORTED_ANNOTATION = %w(wip) - attr_reader :name, :source_language, :target_language + attr_reader :name, :source_language, :target_language, :project def initialize(name, source_language, target_language, project=nil) @name = name Modified: lib/logaling/glossary_db.rb (+13 -5) =================================================================== --- lib/logaling/glossary_db.rb 2012-11-05 11:47:43 +0900 (c18212e) +++ lib/logaling/glossary_db.rb 2012-11-05 19:53:15 +0900 (a88f835) @@ -20,7 +20,7 @@ require 'cgi' module Logaling class GlossaryDB - VERSION = 1 + VERSION = 1.1 def self.open(base_path, encoding, &blk) blk ? GlossaryDB.new.open(base_path, encoding, &blk) : GlossaryDB.new.open(base_path, encoding) @@ -229,10 +229,13 @@ module Logaling def get_all_glossary_sources source_paths = Groonga["glossary_sources"].sort([ {:key=>"_key", :order=>'ascending'} - ]).map{|record| record.key} - source_paths.map do |source_path| + ]).map{|record| {record.key => record.project_type}} + source_paths.map do |tmp_hash| + source_path = tmp_hash.keys.first + project_type = tmp_hash.values.first glossary_name, source_language, target_language = File.basename(source_path).split(/\./) - glossary = Glossary.new(glossary_name, source_language, target_language) + project = Logaling.const_get(project_type).new(Logaling::Project.find_path(source_path)) + glossary = Glossary.new(glossary_name, source_language, target_language, project) GlossarySource.create(source_path, glossary) end end @@ -262,7 +265,11 @@ module Logaling end def add_glossary_source(glossary_source) - Groonga["glossary_sources"].add(glossary_source.source_path, :indexed_at => glossary_source.mtime) + project_type = glossary_source.glossary.project.class.to_s.sub('Logaling::','') + Groonga["glossary_sources"].add( + glossary_source.source_path, { + :indexed_at => glossary_source.mtime, + :project_type => project_type}) end def delete_glossary(glossary_name) @@ -341,6 +348,7 @@ module Logaling :type => :hash, :key_type => "ShortText") do |table| table.time("indexed_at") + table.short_text("project_type") end schema.create_table("glossaries", Modified: lib/logaling/project.rb (+8 -0) =================================================================== --- lib/logaling/project.rb 2012-11-05 11:47:43 +0900 (dc181f5) +++ lib/logaling/project.rb 2012-11-05 19:53:15 +0900 (011919c) @@ -33,6 +33,14 @@ module Logaling end end end + + def find_path(source_path) + if source_path =~ /(.+\/projects\/[^\/]+).+/ + $1 + else + source_path + end + end end attr_reader :path, :repository -------------- next part -------------- An HTML attachment was scrubbed... 下载