localeapp 0.4.1 → 0.4.2
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 +1 -0
- data/CHANGELOG.md +4 -0
- data/bin/localeapp +2 -0
- data/lib/localeapp/cli/pull.rb +1 -1
- data/lib/localeapp/poller.rb +2 -2
- data/lib/localeapp/tasks/localeapp.rake +1 -1
- data/lib/localeapp/updater.rb +1 -1
- data/lib/localeapp/version.rb +1 -1
- data/lib/localeapp.rb +29 -0
- data/spec/fixtures/en.yml +5 -0
- data/spec/localeapp/updater_spec.rb +26 -1
- metadata +4 -4
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# HEAD
|
2
2
|
|
3
|
+
# Version 0.4.1
|
4
|
+
|
5
|
+
* Improve compatibility of Psych with ruby 1.9.2 (Thanks @ardpac)
|
6
|
+
* Ignore HUP when backgrounded. (Thanks @xijo)
|
3
7
|
* Add --standalone option to install to generate a .localeapp/ config
|
4
8
|
directory. This enables usage outside of rails.
|
5
9
|
|
data/bin/localeapp
CHANGED
@@ -125,8 +125,10 @@ command :daemon do |c|
|
|
125
125
|
|
126
126
|
STDOUT.reopen(File.open(Localeapp.configuration.daemon_log_file, 'a'))
|
127
127
|
pid = fork do
|
128
|
+
Signal.trap('HUP', 'IGNORE')
|
128
129
|
command.call
|
129
130
|
end
|
131
|
+
Process.detach(pid)
|
130
132
|
|
131
133
|
File.open(Localeapp.configuration.daemon_pid_file, 'w') {|f| f << pid}
|
132
134
|
else
|
data/lib/localeapp/cli/pull.rb
CHANGED
@@ -21,7 +21,7 @@ module Localeapp
|
|
21
21
|
def update_backend(response)
|
22
22
|
@output.puts "Success!"
|
23
23
|
@output.puts "Updating backend:"
|
24
|
-
Localeapp.updater.update(
|
24
|
+
Localeapp.updater.update(Localeapp.load_yaml(response))
|
25
25
|
@output.puts "Success!"
|
26
26
|
Localeapp.poller.write_synchronization_data!(Time.now.to_i, Time.now.to_i)
|
27
27
|
end
|
data/lib/localeapp/poller.rb
CHANGED
@@ -19,7 +19,7 @@ module Localeapp
|
|
19
19
|
|
20
20
|
def synchronization_data
|
21
21
|
if File.exists?(Localeapp.configuration.synchronization_data_file)
|
22
|
-
|
22
|
+
Localeapp.load_yaml_file(Localeapp.configuration.synchronization_data_file) || {}
|
23
23
|
else
|
24
24
|
{}
|
25
25
|
end
|
@@ -50,7 +50,7 @@ module Localeapp
|
|
50
50
|
|
51
51
|
def handle_success(response)
|
52
52
|
@success = true
|
53
|
-
Localeapp.updater.update(
|
53
|
+
Localeapp.updater.update(Localeapp.load_yaml(response))
|
54
54
|
write_synchronization_data!(Time.now.to_i, Time.parse(response.headers[:date]).to_i)
|
55
55
|
end
|
56
56
|
|
data/lib/localeapp/updater.rb
CHANGED
@@ -8,7 +8,7 @@ module Localeapp
|
|
8
8
|
filename = File.join(Localeapp.configuration.translation_data_directory, "#{short_code}.yml")
|
9
9
|
|
10
10
|
if File.exist?(filename)
|
11
|
-
translations =
|
11
|
+
translations = Localeapp.load_yaml_file(filename)
|
12
12
|
if data['translations'] && data['translations'][short_code]
|
13
13
|
new_data = { short_code => data['translations'][short_code] }
|
14
14
|
translations.deep_merge!(new_data)
|
data/lib/localeapp/version.rb
CHANGED
data/lib/localeapp.rb
CHANGED
@@ -110,5 +110,34 @@ module Localeapp
|
|
110
110
|
false
|
111
111
|
end
|
112
112
|
|
113
|
+
def load_yaml(contents)
|
114
|
+
if defined? Psych
|
115
|
+
Psych.load(contents)
|
116
|
+
else
|
117
|
+
normalize_results(YAML.load(contents))
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def load_yaml_file(filename)
|
122
|
+
load_yaml(File.read(filename))
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def normalize_results(results)
|
128
|
+
if results.is_a?(YAML::PrivateType) && results.type_id == 'null'
|
129
|
+
nil
|
130
|
+
elsif results.is_a?(Array)
|
131
|
+
results.each_with_index do |value, i|
|
132
|
+
results[i] = normalize_results(value)
|
133
|
+
end
|
134
|
+
elsif results.is_a?(Hash)
|
135
|
+
results.each_pair do |key, value|
|
136
|
+
results[key] = normalize_results(value)
|
137
|
+
end
|
138
|
+
else
|
139
|
+
results
|
140
|
+
end
|
141
|
+
end
|
113
142
|
end
|
114
143
|
end
|
data/spec/fixtures/en.yml
CHANGED
@@ -34,19 +34,44 @@ describe Localeapp::Updater, ".update(data)" do
|
|
34
34
|
],
|
35
35
|
'locales' => %w{en es}
|
36
36
|
})
|
37
|
+
|
37
38
|
if defined? Psych
|
38
|
-
|
39
|
+
if Psych::VERSION == '1.0.0'
|
40
|
+
File.read(File.join(@yml_dir, 'en.yml')).should == <<-EN
|
41
|
+
en:
|
42
|
+
foo:
|
43
|
+
monkey: hello
|
44
|
+
night: the night
|
45
|
+
space: !!null
|
46
|
+
blank: ''
|
47
|
+
tilde: !!null
|
48
|
+
scalar1: !!null
|
49
|
+
scalar2: !!null
|
50
|
+
EN
|
51
|
+
else
|
52
|
+
File.read(File.join(@yml_dir, 'en.yml')).should == <<-EN
|
39
53
|
en:
|
40
54
|
foo:
|
41
55
|
monkey: hello
|
42
56
|
night: the night
|
57
|
+
space:
|
58
|
+
blank: ''
|
59
|
+
tilde:
|
60
|
+
scalar1:
|
61
|
+
scalar2:
|
43
62
|
EN
|
63
|
+
end
|
44
64
|
else
|
45
65
|
File.read(File.join(@yml_dir, 'en.yml')).should == <<-EN
|
46
66
|
en:
|
67
|
+
blank: ""
|
47
68
|
foo:
|
48
69
|
monkey: hello
|
49
70
|
night: "the night"
|
71
|
+
scalar1: ~
|
72
|
+
scalar2: ~
|
73
|
+
space: ~
|
74
|
+
tilde: ~
|
50
75
|
EN
|
51
76
|
end
|
52
77
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 2
|
10
|
+
version: 0.4.2
|
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-03-
|
19
|
+
date: 2012-03-16 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: i18n
|