localeapp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -8,4 +8,3 @@ gemfile:
8
8
  branches:
9
9
  only:
10
10
  - master
11
- - develop
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- # HEAD
1
+ # Version 0.3.0
2
+
3
+ * Allow symbols for environment names in config file
4
+ * `localeapp push` will now push all yaml files in a directory if it's given a
5
+ directory instead of a file. (Thanks Bartłomiej Danek)
6
+ * Better daemon support. `daemon_pid_file` and `daemon_log_file` configuration
7
+ options. (Thanks again Bartłomiej Danek)
8
+
9
+ # Version 0.2.0
2
10
 
3
11
  * Add `localeapp add` command for sending keys and translations from the command line
4
12
  * Add `secure` configuration setting for api communications. Default: true
data/bin/localeapp CHANGED
@@ -60,17 +60,17 @@ command :pull do |c|
60
60
  end
61
61
  end
62
62
 
63
- desc "Pushes a translation file to localeapp.com"
63
+ desc "Pushes a translation file or directory to localeapp.com"
64
64
  arg_name "<file>"
65
65
  command :push do |c|
66
66
  c.action do |global_options, options, args|
67
67
  if args.empty?
68
- exit_now! "localeapp push requires an file to push", 1
68
+ exit_now! "localeapp push requires an file or directory to push", 1
69
69
  else
70
- file = args.first
71
70
  include_config_file
71
+ path = args.first
72
72
  pusher = Localeapp::CLI::Push.new
73
- pusher.execute(file)
73
+ pusher.execute(path)
74
74
  end
75
75
  end
76
76
  end
@@ -109,11 +109,22 @@ command :daemon do |c|
109
109
  end
110
110
  end
111
111
  if options[:background]
112
+
113
+ if File.exists? Localeapp.configuration.daemon_pid_file
114
+ begin
115
+ daemon_pid = File.read(Localeapp.configuration.daemon_pid_file)
116
+ Process.kill("QUIT", daemon_pid.to_i)
117
+ rescue Errno::ESRCH
118
+ File.delete(Localeapp.configuration.daemon_pid_file)
119
+ end
120
+ end
121
+
122
+ STDOUT.reopen(File.open(Localeapp.configuration.daemon_log_file, 'a'))
112
123
  pid = fork do
113
124
  command.call
114
125
  end
115
- pids_directory = "tmp/pids"
116
- File.open("#{File.directory?(pids_directory) ? pids_directory : "./"}/localeapp.pid", 'w') {|f| f << pid}
126
+
127
+ File.open(Localeapp.configuration.daemon_pid_file, 'w') {|f| f << pid}
117
128
  else
118
129
  command.call
119
130
  end
@@ -99,7 +99,7 @@ Feature: localeapp executable
99
99
  And help should not be displayed
100
100
  And a file named "config/locales/en.yml" should exist
101
101
 
102
- Scenario: Running push
102
+ Scenario: Running push on a file
103
103
  In order to send my translations
104
104
  When I have a valid project on localeapp.com with api key "MYAPIKEY"
105
105
  And an initializer file
@@ -109,13 +109,36 @@ Feature: localeapp executable
109
109
  """
110
110
  Localeapp Push
111
111
 
112
- Pushing file:
112
+ Pushing file en.yml:
113
113
  Success!
114
114
 
115
115
  config/locales/en.yml queued for processing.
116
116
  """
117
117
  And help should not be displayed
118
118
 
119
+ Scenario: Running push on a directory
120
+ In order to send my translations
121
+ When I have a valid project on localeapp.com with api key "MYAPIKEY"
122
+ And an initializer file
123
+ And an empty file named "config/locales/en.yml"
124
+ And an empty file named "config/locales/es.yml"
125
+ When I run `localeapp push config/locales`
126
+ Then the output should contain:
127
+ """
128
+ Localeapp Push
129
+
130
+ Pushing file en.yml:
131
+ Success!
132
+
133
+ config/locales/en.yml queued for processing.
134
+
135
+ Pushing file es.yml:
136
+ Success!
137
+
138
+ config/locales/es.yml queued for processing.
139
+ """
140
+ And help should not be displayed
141
+
119
142
  Scenario: Running update
120
143
  In order to receive the translations that have been updated since the last check
121
144
  When I have a valid project on localeapp.com with api key "MYAPIKEY"
@@ -1,3 +1,4 @@
1
1
  Before do
2
2
  ENV['FAKE_WEB_DURING_CUCUMBER_RUN'] = '1'
3
+ @aruba_timeout_seconds = 5
3
4
  end
@@ -7,15 +7,23 @@ module Localeapp
7
7
  @output = output
8
8
  end
9
9
 
10
- def execute(file_path = nil)
10
+ def execute(path = nil)
11
11
  @output.puts "Localeapp Push"
12
- @output.puts ""
13
-
14
- @file_path = file_path
12
+ if path_is_directory?(path)
13
+ yaml_files_in_directory(path).each do |path|
14
+ push_file(path)
15
+ end
16
+ else
17
+ push_file(path)
18
+ end
19
+ end
15
20
 
21
+ def push_file(file_path)
22
+ @output.puts ""
23
+ @file_path = file_path # for callbacks
16
24
  file = sanitize_file(file_path)
17
25
  if file
18
- @output.puts "Pushing file:"
26
+ @output.puts "Pushing file #{File.basename(file_path)}:"
19
27
  api_call :import,
20
28
  :payload => { :file => file },
21
29
  :success => :report_success,
@@ -44,6 +52,14 @@ module Localeapp
44
52
  nil
45
53
  end
46
54
  end
55
+
56
+ def path_is_directory?(path)
57
+ File.directory?(path)
58
+ end
59
+
60
+ def yaml_files_in_directory(path)
61
+ Dir.glob(File.join(path, '*.yml')).sort
62
+ end
47
63
  end
48
64
  end
49
65
  end
@@ -1,6 +1,6 @@
1
1
  module Localeapp
2
2
  class Configuration
3
-
3
+
4
4
  # The API key for your project, found on the project edit form
5
5
  attr_accessor :api_key
6
6
 
@@ -83,6 +83,14 @@ module Localeapp
83
83
  # this to RAILS_ROOT/log/localeapp.yml
84
84
  attr_accessor :synchronization_data_file
85
85
 
86
+ # The complete path to the pid file where we store information about daemon
87
+ # default: RAILS_ROOT/tmp/pids/localeapp.pid
88
+ attr_accessor :daemon_pid_file
89
+
90
+ # The complete path to the log file where we store information about daemon actions
91
+ # default: RAILS_ROOT/log/localeapp_daemon.log
92
+ attr_accessor :daemon_log_file
93
+
86
94
  # The complete path to the directory where translations are stored
87
95
  attr_accessor :translation_data_directory
88
96
 
@@ -97,11 +105,13 @@ module Localeapp
97
105
  @disabled_sending_environments = %w(test cucumber production)
98
106
  @disabled_reloading_environments = %w(test cucumber production)
99
107
  @disabled_polling_environments = %w(test cucumber production)
100
- @sending_environments = %w(development)
101
- @reloading_environments = %w(development)
102
- @polling_environments = %w(development)
108
+ @sending_environments = %w(development)
109
+ @reloading_environments = %w(development)
110
+ @polling_environments = %w(development)
103
111
  @poll_interval = 0
104
112
  @synchronization_data_file = File.join('log', 'localeapp.yml')
113
+ @daemon_pid_file = File.join('tmp', 'pids', 'localeapp.pid')
114
+ @daemon_log_file = File.join('log', 'localeapp_daemon.log')
105
115
  @translation_data_directory = File.join('config', 'locales')
106
116
  if ENV['DEBUG']
107
117
  require 'logger'
@@ -112,27 +122,27 @@ module Localeapp
112
122
  def polling_disabled?
113
123
  if deprecated_environment_config_used?
114
124
  ::Localeapp.log "DEPRECATION: disabled_polling_environments is deprecated and will be removed. Use polling_environments instead and reverse the logic if you've changed the defaults"
115
- disabled_polling_environments.include?(environment_name)
125
+ disabled_polling_environments.map { |v| v.to_s }.include?(environment_name)
116
126
  else
117
- !polling_environments.include?(environment_name)
127
+ !polling_environments.map { |v| v.to_s }.include?(environment_name)
118
128
  end
119
129
  end
120
130
 
121
131
  def reloading_disabled?
122
132
  if deprecated_environment_config_used?
123
133
  ::Localeapp.log "DEPRECATION: disabled_reloading_environments is deprecated and will be removed. Use reloading_environments instead and reverse the logic if you've changed the defaults"
124
- disabled_reloading_environments.include?(environment_name)
134
+ disabled_reloading_environments.map { |v| v.to_s }.include?(environment_name)
125
135
  else
126
- !reloading_environments.include?(environment_name)
136
+ !reloading_environments.map { |v| v.to_s }.include?(environment_name)
127
137
  end
128
138
  end
129
139
 
130
140
  def sending_disabled?
131
141
  if deprecated_environment_config_used?
132
142
  ::Localeapp.log "DEPRECATION: disabled_sending_environments is deprecated and will be removed. Use sending_environments instead and reverse the logic if you've changed the defaults"
133
- disabled_sending_environments.include?(environment_name)
143
+ disabled_sending_environments.map { |v| v.to_s }.include?(environment_name)
134
144
  else
135
- !sending_environments.include?(environment_name)
145
+ !sending_environments.map { |v| v.to_s }.include?(environment_name)
136
146
  end
137
147
  end
138
148
 
@@ -1,3 +1,3 @@
1
1
  module Localeapp
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/localeapp.rb CHANGED
@@ -15,7 +15,7 @@ rescue LoadError
15
15
  # This ugliness so we can load AS in the travis env
16
16
  # Assume that we're in rails 2.3 and AS supplies deep_merge
17
17
  # Load AS if we need to
18
- unless @loaded_active_support
18
+ unless @loaded_active_support
19
19
  # we're in 2.3 and we need to load rails to get the vendored i18n
20
20
  require 'thread' # for rubygems > 1.6.0 support
21
21
  require 'active_support'
@@ -33,7 +33,7 @@ require 'localeapp/poller'
33
33
  require 'localeapp/updater'
34
34
  require 'localeapp/key_checker'
35
35
  require 'localeapp/missing_translations'
36
-
36
+
37
37
  require 'localeapp/cli/install'
38
38
  require 'localeapp/cli/pull'
39
39
  require 'localeapp/cli/push'
@@ -52,7 +52,7 @@ module Localeapp
52
52
  class << self
53
53
  # An Localeapp configuration object.
54
54
  attr_accessor :configuration
55
-
55
+
56
56
  # The sender object is responsible for delivering formatted data to the Localeapp server.
57
57
  attr_accessor :sender
58
58
 
@@ -80,7 +80,7 @@ module Localeapp
80
80
  def logger
81
81
  self.configuration && self.configuration.logger
82
82
  end
83
-
83
+
84
84
  # @example Configuration
85
85
  # Localeapp.configure do |config|
86
86
  # config.api_key = '1234567890abcdef'
@@ -1,30 +1,59 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Localeapp::CLI::Push, "#execute(file)" do
4
- before do
5
- @output = StringIO.new
6
- @pusher = Localeapp::CLI::Push.new(@output)
3
+ describe Localeapp::CLI::Push, "#execute(path)" do
4
+ let(:output) { StringIO.new }
5
+ let(:pusher) { Localeapp::CLI::Push.new(output) }
6
+
7
+ context "path is a directory" do
8
+ it "calls push_file on each yaml file in the directory" do
9
+ with_configuration do
10
+ directory = double('directory')
11
+ path = 'test_path'
12
+ yaml_files = %w(en.yml es.yml)
13
+ pusher.stub!(:path_is_directory?).and_return(true)
14
+ pusher.should_receive(:yaml_files_in_directory).with(path).and_return(yaml_files)
15
+ pusher.should_receive(:push_file).with('en.yml')
16
+ pusher.should_receive(:push_file).with('es.yml')
17
+ pusher.execute(path)
18
+ end
19
+ end
7
20
  end
8
21
 
22
+ context "path is a file" do
23
+ it "calls push_file on the file" do
24
+ with_configuration do
25
+ file = double('file')
26
+ file_path = 'test_path'
27
+ pusher.should_receive(:push_file).with(file_path)
28
+ pusher.execute(file_path)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ describe Localeapp::CLI::Push, "#push_file(file_path)" do
35
+ let(:output) { StringIO.new }
36
+ let(:pusher) { Localeapp::CLI::Push.new(output) }
37
+
9
38
  it "creates a new file object and makes the api call to the translations endpoint" do
10
39
  with_configuration do
11
40
  file = double('file')
12
41
  file_path = 'test_path'
13
- @pusher.stub!(:sanitize_file).and_return(file)
14
- @pusher.should_receive(:api_call).with(
42
+ pusher.stub!(:sanitize_file).and_return(file)
43
+ pusher.should_receive(:api_call).with(
15
44
  :import,
16
45
  :payload => { :file => file },
17
46
  :success => :report_success,
18
47
  :failure => :report_failure,
19
48
  :max_connection_attempts => 3
20
49
  )
21
- @pusher.execute(file_path)
50
+ pusher.push_file(file_path)
22
51
  end
23
52
  end
24
53
 
25
54
  it "doesn't make the api call when the file doesn't exist" do
26
- @pusher.stub!(:sanitize_file).and_return(nil)
27
- @pusher.should_not_receive(:api_call)
28
- @pusher.execute('foo')
55
+ pusher.stub!(:sanitize_file).and_return(nil)
56
+ pusher.should_not_receive(:api_call)
57
+ pusher.push_file('foo')
29
58
  end
30
59
  end
@@ -61,6 +61,22 @@ describe Localeapp::Configuration do
61
61
  configuration.translation_data_directory.should == "test"
62
62
  end
63
63
 
64
+ it "sets the daemon_pid_file by default" do
65
+ configuration.daemon_pid_file.should == 'tmp/pids/localeapp.pid'
66
+ end
67
+
68
+ it "allows the daemon_pid_file to be overwritten" do
69
+ expect { configuration.daemon_pid_file = 'foo/la.pid' }.to change(configuration, :daemon_pid_file).to('foo/la.pid')
70
+ end
71
+
72
+ it "sets the daemon_log_file by default" do
73
+ configuration.daemon_log_file.should == 'log/localeapp_daemon.log'
74
+ end
75
+
76
+ it "allows the daemon_log_file to be overwritten" do
77
+ expect { configuration.daemon_log_file = 'log/la.log' }.to change(configuration, :daemon_log_file).to('log/la.log')
78
+ end
79
+
64
80
  context "enabled_sending_environments" do
65
81
  it "is only development by default" do
66
82
  configuration.sending_environments.should == ['development']
@@ -81,7 +97,7 @@ describe Localeapp::Configuration do
81
97
 
82
98
  context "disabled_sending_environments" do
83
99
  it "sets deprecated_environment_config_used flag to true" do
84
- configuration.disabled_sending_environments = %(foo bar)
100
+ configuration.disabled_sending_environments = %w(foo bar)
85
101
  configuration.deprecated_environment_config_used?.should be_true
86
102
  end
87
103
 
@@ -108,7 +124,7 @@ describe Localeapp::Configuration do
108
124
 
109
125
  context "disabled_reloading_environments" do
110
126
  it "sets deprecated_environment_config_used flag to true" do
111
- configuration.disabled_reloading_environments = %(foo bar)
127
+ configuration.disabled_reloading_environments = %w(foo bar)
112
128
  configuration.deprecated_environment_config_used?.should be_true
113
129
  end
114
130
 
@@ -135,7 +151,7 @@ describe Localeapp::Configuration do
135
151
 
136
152
  context "disabled_polling_environments" do
137
153
  it "sets deprecated_environment_config_used flag to true" do
138
- configuration.disabled_polling_environments = %(foo bar)
154
+ configuration.disabled_polling_environments = %w(foo bar)
139
155
  configuration.deprecated_environment_config_used?.should be_true
140
156
  end
141
157
 
@@ -163,27 +179,39 @@ describe Localeapp::Configuration do
163
179
  describe "polling_disabled?" do
164
180
  context "deprecated syntax used" do
165
181
  it "is true when environment is disabled" do
166
- configuration.disabled_polling_environments = %(foo)
182
+ configuration.disabled_polling_environments = %w(foo)
167
183
  configuration.environment_name = 'foo'
168
184
  configuration.should be_polling_disabled
169
185
  end
170
186
 
171
187
  it "is false when environment is not disabled" do
172
- configuration.disabled_polling_environments = %(foo)
188
+ configuration.disabled_polling_environments = %w(foo)
173
189
  configuration.environment_name = 'bar'
174
190
  configuration.should_not be_polling_disabled
175
191
  end
192
+
193
+ it "supports symbols in list of environments" do
194
+ configuration.disabled_polling_environments = [:foo]
195
+ configuration.environment_name = 'foo'
196
+ configuration.should be_polling_disabled
197
+ end
176
198
  end
177
199
 
178
200
  context "new syntax used" do
179
201
  it "is true when environment is not enabled" do
180
- configuration.polling_environments = %(foo)
202
+ configuration.polling_environments = %w(foo)
181
203
  configuration.environment_name = 'bar'
182
204
  configuration.should be_polling_disabled
183
205
  end
184
206
 
185
207
  it "is false when environment is enabled" do
186
- configuration.polling_environments = %(foo)
208
+ configuration.polling_environments = %w(foo)
209
+ configuration.environment_name = 'foo'
210
+ configuration.should_not be_polling_disabled
211
+ end
212
+
213
+ it "supports symbols in list of environments" do
214
+ configuration.polling_environments = [:foo]
187
215
  configuration.environment_name = 'foo'
188
216
  configuration.should_not be_polling_disabled
189
217
  end
@@ -193,27 +221,39 @@ describe Localeapp::Configuration do
193
221
  describe "reloading_disabled?" do
194
222
  context "deprecated syntax used" do
195
223
  it "is true when environment is disabled" do
196
- configuration.disabled_reloading_environments = %(foo)
224
+ configuration.disabled_reloading_environments = %w(foo)
197
225
  configuration.environment_name = 'foo'
198
226
  configuration.should be_reloading_disabled
199
227
  end
200
228
 
201
229
  it "is false when environment is not disabled" do
202
- configuration.disabled_reloading_environments = %(foo)
230
+ configuration.disabled_reloading_environments = %w(foo)
203
231
  configuration.environment_name = 'bar'
204
232
  configuration.should_not be_reloading_disabled
205
233
  end
234
+
235
+ it "supports symbols in list of environments" do
236
+ configuration.disabled_reloading_environments = [:foo]
237
+ configuration.environment_name = 'foo'
238
+ configuration.should be_reloading_disabled
239
+ end
206
240
  end
207
241
 
208
242
  context "new syntax used" do
209
243
  it "is true when environment is not enabled" do
210
- configuration.reloading_environments = %(foo)
244
+ configuration.reloading_environments = %w(foo)
211
245
  configuration.environment_name = 'bar'
212
246
  configuration.should be_reloading_disabled
213
247
  end
214
248
 
215
249
  it "is false when environment is enabled" do
216
- configuration.reloading_environments = %(foo)
250
+ configuration.reloading_environments = %w(foo)
251
+ configuration.environment_name = 'foo'
252
+ configuration.should_not be_reloading_disabled
253
+ end
254
+
255
+ it "supports symbols in list of environments" do
256
+ configuration.reloading_environments = [:foo]
217
257
  configuration.environment_name = 'foo'
218
258
  configuration.should_not be_reloading_disabled
219
259
  end
@@ -223,27 +263,39 @@ describe Localeapp::Configuration do
223
263
  describe "sending_disabled?" do
224
264
  context "deprecated syntax used" do
225
265
  it "is true when environment is disabled" do
226
- configuration.disabled_sending_environments = %(foo)
266
+ configuration.disabled_sending_environments = %w(foo)
227
267
  configuration.environment_name = 'foo'
228
268
  configuration.should be_sending_disabled
229
269
  end
230
270
 
231
271
  it "is false when environment is not disabled" do
232
- configuration.disabled_sending_environments = %(foo)
272
+ configuration.disabled_sending_environments = %w(foo)
233
273
  configuration.environment_name = 'bar'
234
274
  configuration.should_not be_sending_disabled
235
275
  end
276
+
277
+ it "supports symbols in the list of enviroments" do
278
+ configuration.disabled_sending_environments = [:foo]
279
+ configuration.environment_name = 'foo'
280
+ configuration.should be_sending_disabled
281
+ end
236
282
  end
237
283
 
238
284
  context "new syntax used" do
239
285
  it "is true when environment is not enabled" do
240
- configuration.sending_environments = %(foo)
286
+ configuration.sending_environments = %w(foo)
241
287
  configuration.environment_name = 'bar'
242
288
  configuration.should be_sending_disabled
243
289
  end
244
290
 
245
291
  it "is false when environment is enabled" do
246
- configuration.sending_environments = %(foo)
292
+ configuration.sending_environments = %w(foo)
293
+ configuration.environment_name = 'foo'
294
+ configuration.should_not be_sending_disabled
295
+ end
296
+
297
+ it "supports symbols in the list of environments" do
298
+ configuration.sending_environments = [:foo]
247
299
  configuration.environment_name = 'foo'
248
300
  configuration.should_not be_sending_disabled
249
301
  end
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: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
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: 2011-11-17 00:00:00 Z
19
+ date: 2011-11-18 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: i18n