localeapp 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # Version 0.6.7
2
+
3
+ * Add rm and mv commands for deleting / renaming keys from the command line
4
+
1
5
  # Version 0.6.6
2
6
 
3
7
  * Add a timeout configuration setting
data/bin/localeapp CHANGED
@@ -72,6 +72,33 @@ command :add do |c|
72
72
  end
73
73
  end
74
74
 
75
+ desc "removes a key from the project"
76
+ arg_name "<key>"
77
+ command :rm do |c|
78
+ c.action do |global_options, options, args|
79
+ key = args.shift
80
+ if key.nil?
81
+ exit_now! "localeapp rm requires a key name", 1
82
+ else
83
+ Localeapp::CLI::Remove.new(global_options).execute(key, *args)
84
+ end
85
+ end
86
+ end
87
+
88
+ desc "renames a key in the project"
89
+ arg_name "<current key name> <new key name>"
90
+ command :mv do |c|
91
+ c.action do |global_options, options, args|
92
+ current_name = args.shift
93
+ new_name = args.shift
94
+ if current_name.nil? || new_name.nil?
95
+ exit_now! "localeapp mv requires a current key name and a new key name", 1
96
+ else
97
+ Localeapp::CLI::Rename.new(global_options).execute(current_name, new_name, *args)
98
+ end
99
+ end
100
+ end
101
+
75
102
  desc "Pulls all translations from localeapp.com"
76
103
  command :pull do |c|
77
104
  c.action do |global_options, options, args|
@@ -0,0 +1,15 @@
1
+ Feature: Renaming a translation from the command line
2
+
3
+ Scenario: Running mv
4
+ In order to rename an existing key
5
+ When I have a valid project on localeapp.com with api key "MYAPIKEY" and the translation key "foo.bar"
6
+ And an initializer file
7
+ When I run `localeapp mv foo.bar foo.baz`
8
+ Then the output should contain:
9
+ """
10
+ Localeapp mv
11
+
12
+ Renaming key: foo.bar to foo.baz
13
+ Success!
14
+ """
15
+
@@ -0,0 +1,14 @@
1
+ Feature: Removing a translation from the command line
2
+
3
+ Scenario: Running rm
4
+ In order to remove an existing key
5
+ When I have a valid project on localeapp.com with api key "MYAPIKEY" and the translation key "foo.bar"
6
+ And an initializer file
7
+ When I run `localeapp rm foo.bar`
8
+ Then the output should contain:
9
+ """
10
+ Localeapp rm
11
+
12
+ Remove key: foo.bar
13
+ Success!
14
+ """
@@ -27,6 +27,13 @@ When /^new translations for the api key "([^"]*)" since "([^"]*)" with time "([^
27
27
  add_fake_web_uri(:get, uri, ['200', 'OK'], body, 'date' => Time.at(new_time.to_i).httpdate)
28
28
  end
29
29
 
30
+
31
+ When /^I have a valid project on localeapp\.com with api key "([^"]*)" and the translation key "([^"]*)"/ do |api_key, key_name|
32
+ uri = "https://api.localeapp.com/v1/projects/#{api_key}/translations/#{key_name.gsub(/\./, '%2E')}"
33
+ add_fake_web_uri(:delete, uri, ['200', 'OK'], '')
34
+ add_fake_web_uri(:post, uri + '/rename', ['200', 'OK'], '')
35
+ end
36
+
30
37
  When /^an initializer file$/ do
31
38
  steps %Q{
32
39
  And a file named "config/initializers/localeapp.rb" with:
@@ -0,0 +1,26 @@
1
+ module Localeapp
2
+ module CLI
3
+ class Remove < Command
4
+ include ::Localeapp::ApiCall
5
+
6
+ def execute(key, *rest)
7
+ @output.puts "Localeapp rm"
8
+ @output.puts ""
9
+ @output.puts "Remove key: #{key}"
10
+ api_call :remove,
11
+ :url_options => { :key => key },
12
+ :success => :report_success,
13
+ :failure => :report_failure,
14
+ :max_connection_attempts => 3
15
+ end
16
+
17
+ def report_success(response)
18
+ @output.puts "Success!"
19
+ end
20
+
21
+ def report_failure(response)
22
+ @output.puts "Failed!"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ module Localeapp
2
+ module CLI
3
+ class Rename < Command
4
+ include ::Localeapp::ApiCall
5
+
6
+ def execute(current_name, new_name, *rest)
7
+ @output.puts "Localeapp mv"
8
+ @output.puts ""
9
+ @output.puts "Renaming key: #{current_name} to #{new_name}"
10
+ api_call :rename,
11
+ :url_options => { :current_name => current_name },
12
+ :payload => { :new_name => new_name },
13
+ :success => :report_success,
14
+ :failure => :report_failure,
15
+ :max_connection_attempts => 3
16
+ end
17
+
18
+ def report_success(response)
19
+ @output.puts "Success!"
20
+ end
21
+
22
+ def report_failure(response)
23
+ @output.puts "Failed!"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,5 @@
1
+ require 'rack/utils'
2
+
1
3
  module Localeapp
2
4
  module Routes
3
5
  VERSION = 'v1'
@@ -30,6 +32,24 @@ module Localeapp
30
32
  [:get, export_url(options)]
31
33
  end
32
34
 
35
+ def remove_endpoint(options = {})
36
+ [:delete, remove_url(options)]
37
+ end
38
+
39
+ def remove_url(options = {})
40
+ url = http_scheme.build(base_options.merge(:path => remove_path(options[:key], options[:format])))
41
+ url.to_s
42
+ end
43
+
44
+ def rename_endpoint(options = {})
45
+ [:post, rename_url(options)]
46
+ end
47
+
48
+ def rename_url(options = {})
49
+ url = http_scheme.build(base_options.merge(:path => rename_path(options[:current_name], options[:format])))
50
+ url.to_s
51
+ end
52
+
33
53
  def export_url(options = {})
34
54
  options[:format] ||= 'yml'
35
55
  url = http_scheme.build(base_options.merge(:path => export_path(options[:format])))
@@ -85,6 +105,24 @@ module Localeapp
85
105
  path
86
106
  end
87
107
 
108
+ def remove_path(key, format = nil)
109
+ raise "remove_path requires a key" if key.nil?
110
+ path = translations_path << "/#{escape_key(key)}"
111
+ path << ".#{format}" if format
112
+ path
113
+ end
114
+
115
+ def rename_path(current_name, format = nil)
116
+ raise "rename_path requires current name" if current_name.nil?
117
+ path = translations_path << "/#{escape_key(current_name)}" << '/rename'
118
+ path << ".#{format}" if format
119
+ path
120
+ end
121
+
122
+ def escape_key(key)
123
+ Rack::Utils.escape(key).gsub(/\./, '%2E')
124
+ end
125
+
88
126
  def export_path(format = nil)
89
127
  path = project_path << '/translations/all'
90
128
  path << ".#{format}" if format
@@ -1,3 +1,3 @@
1
1
  module Localeapp
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.7"
3
3
  end
data/lib/localeapp.rb CHANGED
@@ -41,6 +41,8 @@ require 'localeapp/cli/pull'
41
41
  require 'localeapp/cli/push'
42
42
  require 'localeapp/cli/update'
43
43
  require 'localeapp/cli/add'
44
+ require 'localeapp/cli/remove'
45
+ require 'localeapp/cli/rename'
44
46
  require 'localeapp/cli/daemon'
45
47
 
46
48
  # AUDIT: Will this work on ruby 1.9.x
data/localeapp.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_dependency('gli')
27
27
 
28
28
  s.add_development_dependency('rake')
29
+ s.add_development_dependency('rack')
29
30
  s.add_development_dependency('rspec', '2.11.0')
30
31
  s.add_development_dependency('yard', '0.6.7')
31
32
  s.add_development_dependency('RedCloth', '4.2.9')
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Localeapp::CLI::Add, "#execute(current_name, new_name, *rest)" do
4
+ def do_action(current_name = 'test.key', new_name = 'test.new_name')
5
+ @command.execute(current_name, new_name)
6
+ end
7
+
8
+ before(:each) do
9
+ @output = StringIO.new
10
+ @command = Localeapp::CLI::Rename.new(:output => @output)
11
+ end
12
+
13
+ it "makes the api call to the translations endpoint with the new name as the post body" do
14
+ with_configuration do
15
+ @command.should_receive(:api_call).with(
16
+ :rename,
17
+ :url_options => { :current_name => 'test.key' },
18
+ :payload => { :new_name => 'test.new_name' },
19
+ :success => :report_success,
20
+ :failure => :report_failure,
21
+ :max_connection_attempts => 3
22
+ )
23
+ do_action
24
+ end
25
+ end
26
+ end
@@ -82,6 +82,42 @@ describe Localeapp::Routes do
82
82
  end
83
83
  end
84
84
 
85
+ describe "#remove_endpoint(options = {})" do
86
+ it "returns :delete and the remove url for the options" do
87
+ with_configuration(@config) do
88
+ options = { :key => 'foo.bar' }
89
+ @routes.should_receive(:remove_url).with(options).and_return('url')
90
+ @routes.remove_endpoint(options).should == [:delete, 'url']
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "#remove_url(options = {})" do
96
+ it "it extends the project_url and includes the escaped key name" do
97
+ with_configuration(@config) do
98
+ @routes.remove_url(:key => 'test.key').should == "https://test.host/v1/projects/API_KEY/translations/test%2Ekey"
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "#rename_endpoint(options = {})" do
104
+ it "returns :post and the rename url for the options" do
105
+ with_configuration(@config) do
106
+ options = { :current_name => 'foo.bar' }
107
+ @routes.should_receive(:rename_url).with(options).and_return('url')
108
+ @routes.rename_endpoint(options).should == [:post, 'url']
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "#rename_url(options = {})" do
114
+ it "it extends the project_url and includes the escaped key name" do
115
+ with_configuration(@config) do
116
+ @routes.rename_url(:current_name => 'test.key').should == "https://test.host/v1/projects/API_KEY/translations/test%2Ekey/rename"
117
+ end
118
+ end
119
+ end
120
+
85
121
  describe "#export_url" do
86
122
  it "it extends the project_url and defaults to yml" do
87
123
  with_configuration(@config) do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localeapp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 6
10
- version: 0.6.6
9
+ - 7
10
+ version: 0.6.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Dell
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-11-08 00:00:00 Z
19
+ date: 2012-11-12 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: i18n
@@ -103,9 +103,23 @@ dependencies:
103
103
  type: :development
104
104
  version_requirements: *id006
105
105
  - !ruby/object:Gem::Dependency
106
- name: rspec
106
+ name: rack
107
107
  prerelease: false
108
108
  requirement: &id007 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ type: :development
118
+ version_requirements: *id007
119
+ - !ruby/object:Gem::Dependency
120
+ name: rspec
121
+ prerelease: false
122
+ requirement: &id008 !ruby/object:Gem::Requirement
109
123
  none: false
110
124
  requirements:
111
125
  - - "="
@@ -117,11 +131,11 @@ dependencies:
117
131
  - 0
118
132
  version: 2.11.0
119
133
  type: :development
120
- version_requirements: *id007
134
+ version_requirements: *id008
121
135
  - !ruby/object:Gem::Dependency
122
136
  name: yard
123
137
  prerelease: false
124
- requirement: &id008 !ruby/object:Gem::Requirement
138
+ requirement: &id009 !ruby/object:Gem::Requirement
125
139
  none: false
126
140
  requirements:
127
141
  - - "="
@@ -133,11 +147,11 @@ dependencies:
133
147
  - 7
134
148
  version: 0.6.7
135
149
  type: :development
136
- version_requirements: *id008
150
+ version_requirements: *id009
137
151
  - !ruby/object:Gem::Dependency
138
152
  name: RedCloth
139
153
  prerelease: false
140
- requirement: &id009 !ruby/object:Gem::Requirement
154
+ requirement: &id010 !ruby/object:Gem::Requirement
141
155
  none: false
142
156
  requirements:
143
157
  - - "="
@@ -149,11 +163,11 @@ dependencies:
149
163
  - 9
150
164
  version: 4.2.9
151
165
  type: :development
152
- version_requirements: *id009
166
+ version_requirements: *id010
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: aruba
155
169
  prerelease: false
156
- requirement: &id010 !ruby/object:Gem::Requirement
170
+ requirement: &id011 !ruby/object:Gem::Requirement
157
171
  none: false
158
172
  requirements:
159
173
  - - "="
@@ -165,11 +179,11 @@ dependencies:
165
179
  - 11
166
180
  version: 0.4.11
167
181
  type: :development
168
- version_requirements: *id010
182
+ version_requirements: *id011
169
183
  - !ruby/object:Gem::Dependency
170
184
  name: fakeweb
171
185
  prerelease: false
172
- requirement: &id011 !ruby/object:Gem::Requirement
186
+ requirement: &id012 !ruby/object:Gem::Requirement
173
187
  none: false
174
188
  requirements:
175
189
  - - "="
@@ -181,7 +195,7 @@ dependencies:
181
195
  - 0
182
196
  version: 1.3.0
183
197
  type: :development
184
- version_requirements: *id011
198
+ version_requirements: *id012
185
199
  description: Synchronizes i18n translation keys and content with localeapp.com so you don't have to manage translations by hand.
186
200
  email:
187
201
  - chris@tigrish.com
@@ -212,8 +226,10 @@ files:
212
226
  - features/bad_command.feature
213
227
  - features/help.feature
214
228
  - features/install.feature
229
+ - features/mv.feature
215
230
  - features/pull.feature
216
231
  - features/push.feature
232
+ - features/rm.feature
217
233
  - features/step_definitions/cli_steps.rb
218
234
  - features/support/env.rb
219
235
  - features/support/hooks.rb
@@ -228,6 +244,8 @@ files:
228
244
  - lib/localeapp/cli/install.rb
229
245
  - lib/localeapp/cli/pull.rb
230
246
  - lib/localeapp/cli/push.rb
247
+ - lib/localeapp/cli/remove.rb
248
+ - lib/localeapp/cli/rename.rb
231
249
  - lib/localeapp/cli/update.rb
232
250
  - lib/localeapp/configuration.rb
233
251
  - lib/localeapp/default_value_handler.rb
@@ -256,6 +274,7 @@ files:
256
274
  - spec/localeapp/cli/install_spec.rb
257
275
  - spec/localeapp/cli/pull_spec.rb
258
276
  - spec/localeapp/cli/push_spec.rb
277
+ - spec/localeapp/cli/rename_spec.rb
259
278
  - spec/localeapp/cli/update_spec.rb
260
279
  - spec/localeapp/configuration_spec.rb
261
280
  - spec/localeapp/default_value_handler_spec.rb
@@ -309,8 +328,10 @@ test_files:
309
328
  - features/bad_command.feature
310
329
  - features/help.feature
311
330
  - features/install.feature
331
+ - features/mv.feature
312
332
  - features/pull.feature
313
333
  - features/push.feature
334
+ - features/rm.feature
314
335
  - features/step_definitions/cli_steps.rb
315
336
  - features/support/env.rb
316
337
  - features/support/hooks.rb
@@ -325,6 +346,7 @@ test_files:
325
346
  - spec/localeapp/cli/install_spec.rb
326
347
  - spec/localeapp/cli/pull_spec.rb
327
348
  - spec/localeapp/cli/push_spec.rb
349
+ - spec/localeapp/cli/rename_spec.rb
328
350
  - spec/localeapp/cli/update_spec.rb
329
351
  - spec/localeapp/configuration_spec.rb
330
352
  - spec/localeapp/default_value_handler_spec.rb