null+****@clear*****
null+****@clear*****
Tue Jun 19 17:46:53 JST 2012
SUZUKI Miho 2012-06-19 17:46:53 +0900 (Tue, 19 Jun 2012) New Revision: c6315dc0fa9b40da402dc081365002f4ec937688 https://github.com/logaling/logaling-command/commit/c6315dc0fa9b40da402dc081365002f4ec937688 Log: Use GlossarySource object in Repository#index Modified files: lib/logaling/project.rb lib/logaling/repository.rb Modified: lib/logaling/project.rb (+13 -0) =================================================================== --- lib/logaling/project.rb 2012-06-19 16:33:22 +0900 (78ce56b) +++ lib/logaling/project.rb 2012-06-19 17:46:53 +0900 (0568e6e) @@ -37,11 +37,24 @@ module Logaling def glossary_db_path @repository.logaling_db_home end + + def glossary_sources + all_glossary_source_path = Dir.glob(File.join(glossary_source_path, "*")) + all_glossary_source_path.map do |source_path| + name, source_language, target_language, type = File.basename(source_path).split(/\./) + GlossarySource.new(source_path, find_glossary(source_language, target_language)) + end + end end class ImportedProject < Project def name File.basename(@path).split(/\./).first end + + def glossary_sources + name, source_language, target_language, type = File.basename(@path).split(/\./) + [GlossarySource.new(@path, find_glossary(source_language, target_language))] + end end end Modified: lib/logaling/repository.rb (+12 -14) =================================================================== --- lib/logaling/repository.rb 2012-06-19 16:33:22 +0900 (8f1157d) +++ lib/logaling/repository.rb 2012-06-19 17:46:53 +0900 (f7f42be) @@ -89,26 +89,24 @@ module Logaling end def index - project_glossaries = Dir[File.join(@path, "projects", "*")].map do |project| - Dir.glob(get_all_glossary_sources(File.join(project, "glossary"))) - end - imported_glossaries = Dir.glob(get_all_glossary_sources(cache_path)) - all_glossaries = project_glossaries.flatten + imported_glossaries + all_glossaries = projects.map{|project| project.glossary_sources}.flatten Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db| db.recreate_table all_glossaries.each do |glossary_source| - indexed_at = File.mtime(glossary_source) - unless db.glossary_source_exist?(glossary_source, indexed_at) - glossary_name, source_language, target_language = get_glossary(glossary_source) - puts "now index #{glossary_name}..." - db.index_glossary(glossary_name, glossary_source, source_language, target_language) + indexed_at = glossary_source.mtime + glossary = glossary_source.glossary + unless db.glossary_source_exist?(glossary_source.source_path, indexed_at) + puts "now index #{glossary.name}..." + db.index_glossary(glossary.name, glossary_source.source_path, glossary.source_language, glossary.target_language) end end - (db.get_all_glossary_source - all_glossaries).each do |glossary_source| - glossary_name, source_language, target_language = get_glossary(glossary_source) - puts "now deindex #{glossary_name}..." - db.deindex_glossary(glossary_name, glossary_source) + (db.get_all_glossary_source - all_glossaries.map(&:source_path)).each do |glossary_source_path| + glossary_name, source_language, target_language = get_glossary(glossary_source_path) + glossary = Logaling::Glossary.new(glossary_name, source_language, target_language) + glossary_source = Logaling::GlossarySource.new(glossary_source_path, glossary) + puts "now deindex #{glossary.name}..." + db.deindex_glossary(glossary.name, glossary_source.source_path) end end end -------------- next part -------------- An HTML attachment was scrubbed... 다운로드