logaling-command 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ = 0.1.9 / 2012-09-28
2
+ * loga copy のショートカットを -C に、loga config のショートカットを -c にしました。
3
+
4
+ * loga update 時に同じ原語・訳語のペアが登録できてしまうことがある不具合を修正しました。
5
+
1
6
  = 0.1.8 / 2012-08-30
2
7
 
3
8
  * 個人用途で logaling-command を使いたい時のために用語集を単体で作れるようにしました。
@@ -55,7 +55,8 @@ module Logaling::Command
55
55
  '-L' => :list,
56
56
  '-s' => :show,
57
57
  '-v' => :version,
58
- '-c' => :copy
58
+ '-c' => :config,
59
+ '-C' => :copy
59
60
 
60
61
  class_option "glossary", type: :string, aliases: "-g"
61
62
  class_option "source-language", type: :string, aliases: "-S"
@@ -188,15 +189,14 @@ module Logaling::Command
188
189
  check_logaling_home_exists
189
190
  project = @repository.find_project(@config.glossary)
190
191
  raise Logaling::ProjectNotFound unless project
191
- raise Logaling::ProjectNotFound if project.class.name == 'Logaling::ImportedProject'
192
+ raise Logaling::ProjectNotFound if project.imported?
192
193
  glossary = project.glossary(@config.source_language, @config.target_language)
193
- if glossary.bilingual_pair_exists?(source_term, target_term)
194
- raise Logaling::TermError, "term '#{source_term}: #{target_term}' already exists in '#{@config.glossary}'"
195
- end
196
194
 
197
195
  glossary.add(source_term, target_term, note)
198
- rescue Logaling::CommandFailed, Logaling::TermError => e
196
+ rescue Logaling::CommandFailed => e
199
197
  say e.message
198
+ rescue Logaling::TermError => e
199
+ say "term '#{source_term}: #{target_term}' already exists in '#{@config.glossary}'"
200
200
  rescue Logaling::GlossaryNotFound => e
201
201
  say "Try 'loga new or register' first."
202
202
  rescue Logaling::ProjectNotFound
@@ -244,13 +244,12 @@ module Logaling::Command
244
244
  project = @repository.find_project(@config.glossary)
245
245
  raise Logaling::ProjectNotFound unless project
246
246
  glossary = project.glossary(@config.source_language, @config.target_language)
247
- if glossary.bilingual_pair_exists?(source_term, new_target_term, note)
248
- raise Logaling::TermError, "term '#{source_term}: #{new_target_term}' already exists in '#{@config.glossary}'"
249
- end
250
247
 
251
248
  glossary.update(source_term, target_term, new_target_term, note)
252
- rescue Logaling::CommandFailed, Logaling::TermError => e
249
+ rescue Logaling::CommandFailed => e
253
250
  say e.message
251
+ rescue Logaling::TermError => e
252
+ say "term '#{source_term}: #{new_target_term}' already exists in '#{@config.glossary}'"
254
253
  rescue Logaling::GlossaryNotFound => e
255
254
  say "Try 'loga new or register' first."
256
255
  rescue Logaling::ProjectNotFound
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Logaling
19
19
  module Command
20
- VERSION = "0.1.8"
20
+ VERSION = "0.1.9"
21
21
  end
22
22
  end
@@ -39,25 +39,35 @@ module Logaling
39
39
  terms
40
40
  end
41
41
 
42
- def bilingual_pair_exists?(source_term, target_term, note=nil)
42
+ def find_bilingual_pairs(source_term, target_term, note=nil)
43
43
  raise Logaling::GlossaryDBNotFound unless File.exist?(@project.glossary_db_path)
44
44
  index
45
45
  terms = []
46
46
  Logaling::GlossaryDB.open(@project.glossary_db_path, "utf8") do |db|
47
47
  terms = db.get_bilingual_pair(source_term, target_term, @name, note)
48
48
  end
49
- !terms.empty?
49
+ terms.delete_if {|t| t[:target_language] != @target_language }
50
+ end
51
+
52
+ def bilingual_pair_exists?(source_term, target_term, note=nil)
53
+ !find_bilingual_pairs(source_term, target_term, note).empty?
50
54
  end
51
55
 
52
56
  def add(source_term, target_term, note)
57
+ raise Logaling::TermError if bilingual_pair_exists?(source_term, target_term)
53
58
  glossary_source.add(source_term, target_term, note)
54
59
  end
55
60
 
56
61
  def update(source_term, target_term, new_target_term, note)
62
+ if (target_term != new_target_term) && bilingual_pair_exists?(source_term, new_target_term)
63
+ raise Logaling::TermError
64
+ end
65
+
57
66
  glossary_source.update(source_term, target_term, new_target_term, note)
58
67
  end
59
68
 
60
69
  def delete(source_term, target_term)
70
+ raise Logaling::TermError unless bilingual_pair_exists?(source_term, target_term)
61
71
  glossary_source.delete(source_term, target_term)
62
72
  end
63
73
 
@@ -122,7 +122,7 @@ module Logaling::GlossarySources
122
122
 
123
123
  def dump_glossary_source(glossary_source)
124
124
  File.open(source_path, "w") do |f|
125
- YAML.dump(glossary_source, f)
125
+ f << YAML.dump(glossary_source)
126
126
  end
127
127
  end
128
128
  end
@@ -76,6 +76,10 @@ module Logaling
76
76
  glossaries.any? {|glossary| glossary.to_s == [name, source_language, target_language].join('.') }
77
77
  end
78
78
 
79
+ def imported?
80
+ false
81
+ end
82
+
79
83
  private
80
84
  def all_glossary_source_path
81
85
  Dir.glob(File.join(glossary_source_path, "*"))
@@ -95,15 +99,29 @@ module Logaling
95
99
  def glossary_source_path
96
100
  File.dirname(@path)
97
101
  end
102
+
103
+ def imported?
104
+ true
105
+ end
98
106
  end
99
107
 
100
108
  class PersonalProject < Project
101
- def self.create(root_path, glossary_name, source_language, target_language)
102
- project_name = [glossary_name, source_language, target_language, 'yml'].join('.')
103
- project_path = File.join(root_path, project_name)
104
- project = PersonalProject.new(project_path)
105
- project.initialize_glossary(source_language, target_language)
106
- project
109
+ class << self
110
+ def create(root_path, glossary_name, source_language, target_language, repository=nil)
111
+ project_name = [glossary_name, source_language, target_language, 'yml'].join('.')
112
+ project_path = File.join(root_path, project_name)
113
+ project = PersonalProject.new(project_path, repository)
114
+ project.initialize_glossary(source_language, target_language)
115
+ project
116
+ end
117
+
118
+ def remove(root_path, glossary_name, source_language, target_language, repository=nil)
119
+ project_name = [glossary_name, source_language, target_language, 'yml'].join('.')
120
+ project_path = File.join(root_path, project_name)
121
+ project = PersonalProject.new(project_path, repository)
122
+ FileUtils.rm_rf(project_path, :secure => true)
123
+ project
124
+ end
107
125
  end
108
126
 
109
127
  def name
@@ -48,7 +48,18 @@ module Logaling
48
48
  if glossary_exists?(project_name, source_language, target_language)
49
49
  raise Logaling::GlossaryAlreadyRegistered, "The glossary '#{project_name}' already exists."
50
50
  end
51
- PersonalProject.create(personal_glossary_root_path, project_name, source_language, target_language)
51
+ PersonalProject.create(personal_glossary_root_path, project_name, source_language, target_language, self)
52
+ end
53
+
54
+ def remove_personal_project(project_name, source_language, target_language)
55
+ unless glossary_exists?(project_name, source_language, target_language)
56
+ raise Logaling::GlossaryNotFound, "The glossary '#{project_name}' not found."
57
+ end
58
+ PersonalProject.remove(personal_glossary_root_path, project_name, source_language, target_language, self)
59
+ rescue Logaling::GlossaryNotFound => e
60
+ raise e
61
+ rescue
62
+ raise Logaling::CommandFailed, "Failed remove the glossary #{project_name}."
52
63
  end
53
64
 
54
65
  def import(glossary_source)
@@ -99,7 +110,7 @@ module Logaling
99
110
  end
100
111
 
101
112
  def index
102
- all_glossary_sources = projects.map{|project| project.glossary_sources}.flatten
113
+ all_glossary_sources = projects.map {|project| project.glossary_sources }.flatten
103
114
 
104
115
  Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
105
116
  db.recreate_table
@@ -128,7 +139,7 @@ module Logaling
128
139
  end
129
140
 
130
141
  def find_project(project_name)
131
- project = projects.detect{|project| project.name == project_name}
142
+ projects.detect {|project| project.name == project_name }
132
143
  end
133
144
 
134
145
  def find_glossary(project_name, source_language, target_language)
@@ -341,11 +341,12 @@ describe Logaling::Command::Application do
341
341
 
342
342
  context 'with exisiting bilingual pair and note' do
343
343
  before do
344
- @stdout = capture(:stdout) { command.update("spec", "テスト", "テスト", "備考") }
344
+ command.update("spec", "テスト", "テスト", "備考")
345
+ @yaml = YAML::load_file(glossary_source_path).find{|h| h["source_term"] == "spec" }
345
346
  end
346
347
 
347
- it 'should show error message' do
348
- @stdout.should include "already exists"
348
+ it "term's target_term should not be updated" do
349
+ @yaml.should == {"source_term"=>"spec", "target_term"=>"テスト", "note"=>"備考"}
349
350
  end
350
351
  end
351
352
 
@@ -89,7 +89,16 @@ module Logaling
89
89
  term = yaml.index({"source_term"=>"user", "target_term"=>"ユーザ", "note"=>""})
90
90
  term.should_not be_nil
91
91
  end
92
+ end
93
+
94
+ context 'same [source-term, taget-term] pair can not exist' do
95
+ before do
96
+ glossary.add("user", "ゆーざー", "")
97
+ end
92
98
 
99
+ it {
100
+ -> { glossary.update("user", "ゆーざー", "ユーザ", "") }.should raise_error(Logaling::TermError)
101
+ }
93
102
  end
94
103
  end
95
104
 
@@ -98,6 +107,8 @@ module Logaling
98
107
  before do
99
108
  glossary.add("delete_logaling", "てすと1", "備考")
100
109
  glossary.add("delete_logaling", "てすと2", "備考")
110
+ # in order to index certainly
111
+ sleep(1)
101
112
  glossary.delete("delete_logaling", "てすと1")
102
113
  repository.index
103
114
  @result = repository.lookup("delete_logaling", glossary)
@@ -118,6 +118,8 @@ module Logaling
118
118
  File.open(glossary_source_path, 'w') do |f|
119
119
  YAML.dump([], f)
120
120
  end
121
+ # in order to index certainly
122
+ sleep(1)
121
123
  glossary.add("spec_logaling", "スペック", "備考")
122
124
  repository.index
123
125
  @terms = repository.lookup("spec_logaling", glossary)
@@ -167,6 +169,36 @@ module Logaling
167
169
  end
168
170
  end
169
171
 
172
+ describe "#remove_personal_project" do
173
+ let(:rm_glossary_name) { "rm_personal_project" }
174
+ let(:rm_source_language) { "en" }
175
+ let(:rm_target_language) { "ja" }
176
+ before do
177
+ FileUtils.rm_rf(File.join(logaling_home, 'personal'), :secure => true)
178
+ repository.create_personal_project(rm_glossary_name, rm_source_language, rm_target_language)
179
+ end
180
+
181
+ context "when target personal project exists" do
182
+ before do
183
+ repository.remove_personal_project(rm_glossary_name, rm_source_language, rm_target_language)
184
+ @projects = repository.projects
185
+ end
186
+
187
+ it "should remove personal project" do
188
+ @projects.size.should == 1
189
+ end
190
+ end
191
+
192
+ context "when target personal project not exist" do
193
+ it "should raise Logaling::GlossaryNotFound" do
194
+ @name = rm_glossary_name + "foo"
195
+ lambda{
196
+ repository.remove_personal_project(@name, rm_source_language, rm_target_language)
197
+ }.should raise_error(Logaling::GlossaryNotFound)
198
+ end
199
+ end
200
+ end
201
+
170
202
  after do
171
203
  FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'), :secure => true)
172
204
  end
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.8
4
+ version: 0.1.9
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-08-30 00:00:00.000000000 Z
16
+ date: 2012-09-28 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: thor