logaling-command 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ = 0.2.0 / 2012-10-29
2
+ * lookup 時のオプションに --fixed を追加しました。
3
+ * 言語対のみ異なる個人用語集を削除した場合に、削除されなかった方の個人用語集もdeindexされてしまう不具合を修正しました。
4
+
1
5
  = 0.1.9 / 2012-09-28
2
6
  * loga copy のショートカットを -C に、loga config のショートカットを -c にしました。
3
7
 
@@ -262,6 +262,7 @@ module Logaling::Command
262
262
  method_option "no-pager", type: :boolean, default: false
263
263
  method_option "no-color", type: :boolean, default: false
264
264
  method_option "dictionary", type: :boolean, default: false, aliases: "--dict"
265
+ method_option "fixed", type: :boolean, default: false
265
266
  def lookup(source_term)
266
267
  check_logaling_home_exists
267
268
  @repository.index
@@ -272,7 +273,7 @@ module Logaling::Command
272
273
  else
273
274
  glossary = nil
274
275
  end
275
- terms = @repository.lookup(source_term, glossary, options["dictionary"])
276
+ terms = @repository.lookup(source_term, glossary, options)
276
277
  unless terms.empty?
277
278
  run_pager
278
279
  terms.each_with_index do |term, i|
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Logaling
19
19
  module Command
20
- VERSION = "0.1.9"
20
+ VERSION = "0.2.0"
21
21
  end
22
22
  end
@@ -101,12 +101,15 @@ module Logaling
101
101
  [@name, @source_language, @target_language].join('.')
102
102
  end
103
103
 
104
- private
105
- def index
104
+ def index!
105
+ index(force: true)
106
+ end
107
+
108
+ def index(options = { force: false })
106
109
  Logaling::GlossaryDB.open(@project.glossary_db_path, "utf8") do |db|
107
110
  db.recreate_table
108
111
  glossary_sources.each do |glossary_source|
109
- unless db.glossary_source_exist?(glossary_source)
112
+ if !db.glossary_source_exist?(glossary_source) || options[:force] == true
110
113
  puts "now index #{@name}..."
111
114
  db.index_glossary_source(glossary_source)
112
115
  end
@@ -119,6 +122,7 @@ module Logaling
119
122
  end
120
123
  end
121
124
 
125
+ private
122
126
  def glossary_sources
123
127
  glob_condition = SUPPORTED_FILE_TYPE.map do |type|
124
128
  file_name = [self.to_s, type].join('.')
@@ -63,8 +63,10 @@ module Logaling
63
63
 
64
64
  def deindex_glossary(glossary, glossary_source)
65
65
  delete_translations_by_glossary_source(glossary_source.source_path)
66
- delete_glossary(glossary.name)
67
66
  delete_glossary_source(glossary_source.source_path)
67
+ unless glossary_source_of_the_same_project_exist?(glossary_source)
68
+ delete_glossary(glossary.name)
69
+ end
68
70
  end
69
71
 
70
72
  def deindex_glossary_source(glossary_source)
@@ -437,5 +439,24 @@ module Logaling
437
439
  # use online index if LOGALING_OFFLINE_INDEX=no
438
440
  ENV["LOGALING_OFFLINE_INDEX"] != "no"
439
441
  end
442
+
443
+ def glossary_source_of_the_same_project_exist?(glossary_source)
444
+ glossary_source_num = 0
445
+ get_all_glossary_sources.each do |glossary_source_taken|
446
+ if glossary_source.belongs_to_personal? && glossary_source_taken.belongs_to_personal?
447
+ if glossary_source.glossary_name == glossary_source_taken.glossary_name
448
+ glossary_source_num = 1
449
+ break
450
+ end
451
+ elsif glossary_source.belongs_to_project? && glossary_source_taken.belongs_to_project?
452
+ if glossary_source.project_name == glossary_source_taken.project_name &&
453
+ glossary_source.glossary_name == glossary_source_taken.glossary_name
454
+ glossary_source_num = 1
455
+ break
456
+ end
457
+ end
458
+ end
459
+ glossary_source_num > 0 ? true : false
460
+ end
440
461
  end
441
462
  end
@@ -37,6 +37,22 @@ module Logaling
37
37
  def mtime
38
38
  File.mtime(@source_path)
39
39
  end
40
+
41
+ def belongs_to_personal?
42
+ @source_path =~ /.+\/personal\/.+/ ? true : false
43
+ end
44
+
45
+ def belongs_to_project?
46
+ @source_path =~ /.+\/projects\/.+/ ? true : false
47
+ end
48
+
49
+ def glossary_name
50
+ File.basename(@source_path).split(".", 2)[0]
51
+ end
52
+
53
+ def project_name
54
+ @source_path =~ /.+\/projects\/([^\/]+).+/ ? $1 : nil
55
+ end
40
56
  end
41
57
  end
42
58
  end
@@ -82,18 +82,25 @@ module Logaling
82
82
  raise Logaling::CommandFailed, "Failed import_tmx #{glossary_source.class.name} to #{cache_path}."
83
83
  end
84
84
 
85
- def lookup(source_term, glossary, dictionary=false)
85
+ def lookup(source_term, glossary, options={})
86
86
  raise Logaling::GlossaryDBNotFound unless File.exist?(logaling_db_home)
87
87
 
88
88
  terms = []
89
89
  Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
90
- if dictionary
90
+ if options['dictionary']
91
91
  terms = db.lookup_dictionary(source_term)
92
92
  else
93
93
  terms = db.lookup(source_term, glossary)
94
94
  end
95
95
  end
96
- terms
96
+ options['fixed'] ? except_annotation(terms) : terms
97
+ end
98
+
99
+ def except_annotation(terms)
100
+ fixed_terms = terms.reject do |term|
101
+ Logaling::Glossary::SUPPORTED_ANNOTATION.any? {|ann| term[:note].index(ann) }
102
+ end
103
+ fixed_terms
97
104
  end
98
105
 
99
106
  def projects
@@ -54,7 +54,8 @@ module Logaling
54
54
  glossary.add("ゆーざ", "test user-logaling test text", "")
55
55
  File.stub!(:mtime).and_return(Time.now - 1)
56
56
  repository.index
57
- @terms = repository.lookup("user-logaling", glossary, true)
57
+ options = {"dictionary"=>true}
58
+ @terms = repository.lookup("user-logaling", glossary, options)
58
59
  @result = [{
59
60
  :glossary_name=>"spec",
60
61
  :source_language=>"en",
@@ -89,6 +90,32 @@ module Logaling
89
90
  end
90
91
  end
91
92
 
93
+ context 'with fixed option' do
94
+ let(:annotation_word) { Logaling::Glossary::SUPPORTED_ANNOTATION.first }
95
+ before do
96
+ glossary.add("user", "ユーザ", "ユーザーではない")
97
+ glossary.add("user-logaling", "ユーザ", "ユーザーと迷い中 #{annotation_word}")
98
+ File.stub!(:mtime).and_return(Time.now - 1)
99
+ repository.index
100
+ options = {"fixed" => true}
101
+ @terms = repository.lookup("user", glossary, options)
102
+ @result = [{
103
+ :glossary_name=>"spec",
104
+ :source_language=>"en",
105
+ :target_language=>"ja",
106
+ :source_term=>"user",
107
+ :snipped_source_term=>["", {:keyword=>"user"}],
108
+ :target_term=>"ユーザ",
109
+ :snipped_target_term=>["ユーザ"],
110
+ :note=>"ユーザーではない"}]
111
+ end
112
+
113
+ it 'succeed at find by term without include annotation' do
114
+ @terms.should == @result
115
+ end
116
+
117
+ end
118
+
92
119
  context 'when tsv file as glossary exists' do
93
120
  let(:tsv_path) { glossary_source_path.sub(/yml$/, 'tsv') }
94
121
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logaling-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-09-28 00:00:00.000000000 Z
16
+ date: 2012-10-29 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: thor