translator_with_localeapp 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +5 -1
- data/Rakefile +1 -0
- data/lib/translator/synchronizer.rb +16 -4
- data/lib/translator/version.rb +1 -1
- data/spec/helpers/test_data/file1.yml +2 -0
- data/spec/helpers/test_data/file2.yml +2 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/translator/null_stream_spec.rb +18 -0
- data/spec/translator/store_spec.rb +60 -0
- data/spec/translator/synchronizer_spec.rb +90 -0
- data/spec/translator/yaml_file_flattener_spec.rb +17 -0
- data/spec/translator_spec.rb +64 -0
- data/translator.gemspec +7 -3
- metadata +61 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 787b142325f9c37a78279d612dcbf9c2907869da
|
4
|
+
data.tar.gz: c02c9a17a1da150c276c8e8443d8fdb523d65cf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50f25f941e07140ebe6b68c4acbe3e3d0d0fe8e2a689f1ea54e95df83c162a42a63bc2faa2cd9e66b461e40455bd1997c84e55e98d1dabb6542fc396280c8c84
|
7
|
+
data.tar.gz: eb32d162808540c111d63453d6b5dab8fee822bfd62fa532c530f24f3837a0ff687f562e5e5241739b594e6d747c4ec1f985c30fc3facf8c920f77f6862790c7
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'localeapp'
|
2
|
+
|
1
3
|
module Translator
|
2
4
|
class Synchronizer
|
3
5
|
attr_reader :paths, :output_stream
|
@@ -12,14 +14,25 @@ module Translator
|
|
12
14
|
end
|
13
15
|
|
14
16
|
private
|
17
|
+
def pusher
|
18
|
+
@pusher ||= ::Localeapp::CLI::Push.new(output: output_stream)
|
19
|
+
end
|
20
|
+
|
21
|
+
def puller
|
22
|
+
@puller ||= Localeapp::CLI::Pull.new(output: output_stream)
|
23
|
+
end
|
24
|
+
|
25
|
+
def updator
|
26
|
+
@updator ||= Localeapp::CLI::Update.new(output: output_stream)
|
27
|
+
end
|
28
|
+
|
15
29
|
def push
|
16
|
-
pusher = ::Localeapp::CLI::Push.new(output: output_stream)
|
17
30
|
paths.each { |path| pusher.execute(path) }
|
18
31
|
end
|
19
32
|
|
20
33
|
def update
|
21
34
|
pull unless pulled?
|
22
|
-
|
35
|
+
updator.execute
|
23
36
|
end
|
24
37
|
|
25
38
|
def pull
|
@@ -27,7 +40,7 @@ module Translator
|
|
27
40
|
FileUtils.mkdir_p(Translator.data_directory)
|
28
41
|
FileUtils.mkdir_p(Pathname.new(Translator.synchronization_data_file).parent)
|
29
42
|
File.open(Translator.synchronization_data_file, 'w') { }
|
30
|
-
|
43
|
+
puller.execute
|
31
44
|
end
|
32
45
|
|
33
46
|
def pulled?
|
@@ -37,6 +50,5 @@ module Translator
|
|
37
50
|
def resolve_path(path)
|
38
51
|
File.expand_path(path, __FILE__)
|
39
52
|
end
|
40
|
-
|
41
53
|
end
|
42
54
|
end
|
data/lib/translator/version.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'byebug'
|
3
|
+
require 'simplecov'
|
4
|
+
require 'translator'
|
5
|
+
SimpleCov.start
|
6
|
+
|
7
|
+
Translator.setup do |config|
|
8
|
+
config.synchronization_data_file = File.expand_path('../.localeapp/log.yml', __FILE__)
|
9
|
+
config.data_directory = File.expand_path('../locales', __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.after(:all) do
|
14
|
+
FileUtils.rm_rf(Translator.data_directory)
|
15
|
+
FileUtils.rm_rf(Pathname.new(Translator.synchronization_data_file).parent)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Translator::NullStream do
|
4
|
+
let(:subject) { Translator::NullStream.new }
|
5
|
+
|
6
|
+
describe '#puts' do
|
7
|
+
it 'does not print' do
|
8
|
+
expect(subject.puts("Test")).to eq(nil)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'Aliasing' do
|
13
|
+
it 'write and << are aliases of puts' do
|
14
|
+
expect(subject.method(:write)).to eq(subject.method(:puts))
|
15
|
+
expect(subject.method(:<<)).to eq(subject.method(:puts))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Translator::Store do
|
4
|
+
let(:store) { Translator::Store.instance }
|
5
|
+
|
6
|
+
before { store.clear }
|
7
|
+
|
8
|
+
describe '#write' do
|
9
|
+
before { store.write('first_name', nil) }
|
10
|
+
|
11
|
+
it 'writes to the storage' do
|
12
|
+
store.write('first_name', 'Kuldeep')
|
13
|
+
expect(store.read('first_name')).to eq('Kuldeep')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#read' do
|
18
|
+
context 'storage has nothing as data' do
|
19
|
+
it 'returns nil' do
|
20
|
+
expect(store.read('first_name')).to eq(nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'storage has something as data' do
|
25
|
+
before do
|
26
|
+
store.write('first_name', 'Kuldeep')
|
27
|
+
store.write('lastname', nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'lastname is nil' do
|
31
|
+
expect(store.read('lastname')).to eq(nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'first_name == Kuldeep' do
|
35
|
+
expect(store.read('first_name')).to eq('Kuldeep')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#load_files' do
|
41
|
+
let(:yaml_data) {
|
42
|
+
{
|
43
|
+
en: { first_name: 'Kuldeep' },
|
44
|
+
pa: { first_name: 'ਕੁਲਦੀਪ' }
|
45
|
+
}
|
46
|
+
}
|
47
|
+
before do
|
48
|
+
allow_any_instance_of(Translator::YamlFileFlattener).to receive(:process).and_return(yaml_data)
|
49
|
+
end
|
50
|
+
after do
|
51
|
+
store.clear
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'loads all yml files in the storage' do
|
55
|
+
store.load_files(nil)
|
56
|
+
expect(store[:en]).to eq(first_name: 'Kuldeep')
|
57
|
+
expect(store[:pa]).to eq(first_name: 'ਕੁਲਦੀਪ')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestSynchronizer
|
4
|
+
def execute(*args); end
|
5
|
+
end
|
6
|
+
|
7
|
+
class TestPusher < TestSynchronizer; end
|
8
|
+
class TestPuller < TestSynchronizer; end
|
9
|
+
class TestUpdator < TestSynchronizer; end
|
10
|
+
|
11
|
+
describe Translator::Synchronizer do
|
12
|
+
let(:file_paths) { Dir[File.expand_path('../../helpers/test_data/*.yml', __FILE__)] }
|
13
|
+
let(:synchronizer) do
|
14
|
+
syn = Translator::Synchronizer.new(file_paths)
|
15
|
+
syn.instance_eval do
|
16
|
+
def puller
|
17
|
+
@puller ||= TestPuller.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def pusher
|
21
|
+
@pusher ||= TestPusher.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def updator
|
25
|
+
@updator ||= TestUpdator.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
syn
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#process' do
|
32
|
+
it 'pushes and updates all files for processing' do
|
33
|
+
expect(synchronizer).to receive(:push)
|
34
|
+
expect(synchronizer).to receive(:update)
|
35
|
+
synchronizer.process
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#push' do
|
40
|
+
it 'pushes all file by Localeapp' do
|
41
|
+
expect(synchronizer.pusher).to receive(:execute).exactly(file_paths.count).times
|
42
|
+
synchronizer.send(:push)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#update' do
|
47
|
+
context 'when ever pulled' do
|
48
|
+
before { allow(synchronizer).to receive(:pulled?).and_return(true) }
|
49
|
+
|
50
|
+
it 'does not pull the files' do
|
51
|
+
expect(synchronizer).to_not receive(:pull)
|
52
|
+
synchronizer.send(:update)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when pulled neever' do
|
57
|
+
before { allow(synchronizer).to receive(:pulled?).and_return(false) }
|
58
|
+
after { FileUtils.rm_rf(Pathname.new(Translator.synchronization_data_file).parent) }
|
59
|
+
|
60
|
+
it 'pulls the file' do
|
61
|
+
expect(synchronizer.puller).to receive(:execute)
|
62
|
+
synchronizer.send(:update)
|
63
|
+
expect(File.exist?(Translator.synchronization_data_file)).to eq(true)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'updates the files' do
|
68
|
+
expect(synchronizer.updator).to receive(:execute)
|
69
|
+
synchronizer.send(:update)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#puller' do
|
74
|
+
it 'is an instance of Localeapp::CLI::Pull' do
|
75
|
+
expect(Translator::Synchronizer.new([]).send(:puller)).to be_an_instance_of(Localeapp::CLI::Pull)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#pusher' do
|
80
|
+
it 'is an instance of Localeapp::CLI::Push' do
|
81
|
+
expect(Translator::Synchronizer.new([]).send(:pusher)).to be_an_instance_of(Localeapp::CLI::Push)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#updator' do
|
86
|
+
it 'is an instance of Localeapp::CLI::Update' do
|
87
|
+
expect(Translator::Synchronizer.new([]).send(:updator)).to be_an_instance_of(Localeapp::CLI::Update)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Translator::YamlFileFlattener do
|
4
|
+
describe '#process' do
|
5
|
+
let(:file_paths) { Dir[File.expand_path('../../helpers/test_data/*.yml', __FILE__)] }
|
6
|
+
let(:flattener) { Translator::YamlFileFlattener.new(file_paths) }
|
7
|
+
|
8
|
+
it 'merges all yaml files data' do
|
9
|
+
expect(flattener.process).to eq({
|
10
|
+
'en' => {
|
11
|
+
'first_name' => 'Kuldeep',
|
12
|
+
'last_name' => 'Aggarwal'
|
13
|
+
}
|
14
|
+
})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Translator do
|
4
|
+
it 'has default Redis Storage' do
|
5
|
+
expect(Translator.storage).to be :Redis
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'has default storage options' do
|
9
|
+
expect(Translator.storage_options).to eq({ host: 'localhost', port: 6379, db: 1 })
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'has output stream' do
|
13
|
+
expect(Translator).to respond_to(:output_stream)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has default Null output stream' do
|
17
|
+
expect(Translator.default_output_stream).to be_an_instance_of(Translator::NullStream)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has a log file in the .localapp folder' do
|
21
|
+
expect(Translator.synchronization_data_file).to_not be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'syncs the data in data directory' do
|
25
|
+
expect(Translator.data_directory).to eq(File.expand_path('../../spec/locales', __FILE__))
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'does not have localeapp api key' do
|
29
|
+
expect(Translator.localeapp_api_key).to be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'Class Methods' do
|
33
|
+
before do
|
34
|
+
FileUtils.mkdir_p(Translator.data_directory)
|
35
|
+
end
|
36
|
+
|
37
|
+
after { FileUtils.rm_rf(Translator.data_directory) }
|
38
|
+
|
39
|
+
describe '.default_file_paths' do
|
40
|
+
let(:file_path) { "#{ Translator.data_directory }/_test.yml" }
|
41
|
+
|
42
|
+
before do
|
43
|
+
File.open(file_path, 'w') {}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns all .yml file paths in the data directory' do
|
47
|
+
expect(Translator.default_file_paths).to eq([file_path])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.load!' do
|
52
|
+
after { Translator.load!(nil) }
|
53
|
+
|
54
|
+
it 'synchronizes locale files from the server' do
|
55
|
+
expect_any_instance_of(Translator::Synchronizer).to receive(:process).and_return(true)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'loads the locale in the store' do
|
59
|
+
allow_any_instance_of(Translator::Synchronizer).to receive(:process).and_return(true)
|
60
|
+
expect(Translator::Store.instance).to receive(:load_files).with(nil)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/translator.gemspec
CHANGED
@@ -22,7 +22,11 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.required_ruby_version = '>= 1.9.3'
|
24
24
|
|
25
|
-
s.add_dependency
|
26
|
-
s.add_dependency
|
27
|
-
s.add_dependency
|
25
|
+
s.add_dependency 'localeapp', '~> 0.9'
|
26
|
+
s.add_dependency 'moneta', '~> 0.8'
|
27
|
+
s.add_dependency 'activesupport', '>= 3.2', '< 5'
|
28
|
+
|
29
|
+
s.add_development_dependency 'bundler', '~> 1.6'
|
30
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
s.add_development_dependency 'rspec', '~> 3.2.0', '>= 3.1.0'
|
28
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translator_with_localeapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuldeep Aggarwal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: localeapp
|
@@ -58,6 +58,54 @@ dependencies:
|
|
58
58
|
- - <
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '5'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.6'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.6'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ~>
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '10.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '10.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ~>
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 3.2.0
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 3.1.0
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ~>
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 3.2.0
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 3.1.0
|
61
109
|
description: Flexible syncronization solution of locales with LocaleApp.
|
62
110
|
email:
|
63
111
|
- kd.engineer@yahoo.co.in
|
@@ -66,15 +114,26 @@ extensions: []
|
|
66
114
|
extra_rdoc_files: []
|
67
115
|
files:
|
68
116
|
- .gitignore
|
117
|
+
- .rspec
|
118
|
+
- .travis.yml
|
69
119
|
- Gemfile
|
70
120
|
- LICENSE.txt
|
71
121
|
- README.md
|
122
|
+
- Rakefile
|
72
123
|
- lib/translator.rb
|
73
124
|
- lib/translator/null_stream.rb
|
74
125
|
- lib/translator/store.rb
|
75
126
|
- lib/translator/synchronizer.rb
|
76
127
|
- lib/translator/version.rb
|
77
128
|
- lib/translator/yaml_file_flattener.rb
|
129
|
+
- spec/helpers/test_data/file1.yml
|
130
|
+
- spec/helpers/test_data/file2.yml
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
- spec/translator/null_stream_spec.rb
|
133
|
+
- spec/translator/store_spec.rb
|
134
|
+
- spec/translator/synchronizer_spec.rb
|
135
|
+
- spec/translator/yaml_file_flattener_spec.rb
|
136
|
+
- spec/translator_spec.rb
|
78
137
|
- translator.gemspec
|
79
138
|
homepage: https://github.com/kuldeepaggarwal/translator
|
80
139
|
licenses:
|