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 CHANGED
@@ -1,5 +1,6 @@
1
1
  rvm:
2
2
  - 1.8.7
3
+ - 1.9.2
3
4
  - 1.9.3
4
5
  gemfile:
5
6
  - Gemfile.i18n_037
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
@@ -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(YAML.load(response))
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
@@ -19,7 +19,7 @@ module Localeapp
19
19
 
20
20
  def synchronization_data
21
21
  if File.exists?(Localeapp.configuration.synchronization_data_file)
22
- YAML.load_file(Localeapp.configuration.synchronization_data_file) || {}
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(YAML.load(response))
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
 
@@ -3,7 +3,7 @@ namespace :localeapp do
3
3
  task :import => :environment do
4
4
  require 'flatten'
5
5
  include I18n::Backend::Flatten
6
- yml = YAML.load_file(ENV['LOCALE_FILE'])
6
+ yml = Locale.load_yaml_file(ENV['LOCALE_FILE'])
7
7
 
8
8
  yml.each do |locale, translations|
9
9
  flatten_translations(
@@ -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 = YAML.load(File.read(filename))
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)
@@ -1,3 +1,3 @@
1
1
  module Localeapp
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
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
@@ -4,3 +4,8 @@ en:
4
4
  foo:
5
5
  delete_me: Delete
6
6
  monkey: Monkey
7
+ space:
8
+ blank: ''
9
+ tilde: ~
10
+ scalar1: !null
11
+ scalar2: !!null
@@ -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
- File.read(File.join(@yml_dir, 'en.yml')).should == <<-EN
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: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
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-02 00:00:00 Z
19
+ date: 2012-03-16 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: i18n