translator_with_localeapp 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec29e837e47f36f1b8ec77af4a95107519578e30
4
- data.tar.gz: fd296837f7d3a2df0f4db78768e27dd151363ab4
3
+ metadata.gz: 787b142325f9c37a78279d612dcbf9c2907869da
4
+ data.tar.gz: c02c9a17a1da150c276c8e8443d8fdb523d65cf2
5
5
  SHA512:
6
- metadata.gz: 06f6c3fef7926e466b7525d544deefaed3cbc23535c3070a4ef087e866e33ba383c6b453fcdda84fcd6ef78270ad57c7e2e4184a9709d4b28163253b20717b71
7
- data.tar.gz: c3781148eebedb327930d636c9d310e56d3f567bf7ceb9ecdb869a3dc861eb0ece7925da54be290567884792bb7839316c4903a43587c5b7d1d9db4a7d698a59
6
+ metadata.gz: 50f25f941e07140ebe6b68c4acbe3e3d0d0fe8e2a689f1ea54e95df83c162a42a63bc2faa2cd9e66b461e40455bd1997c84e55e98d1dabb6542fc396280c8c84
7
+ data.tar.gz: eb32d162808540c111d63453d6b5dab8fee822bfd62fa532c530f24f3837a0ff687f562e5e5241739b594e6d747c4ec1f985c30fc3facf8c920f77f6862790c7
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  locales/
3
3
  .localeapp/
4
4
  Gemfile.lock
5
+ *.gem
6
+ /coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ services:
3
+ - redis
4
+ rvm:
5
+ - 2.1.6
6
+ - 2.2.0
7
+ script:
8
+ - bundle
9
+ - bundle exec rspec .
data/Gemfile CHANGED
@@ -2,7 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :development do
5
+ group :development, :test do
6
6
  gem 'redis'
7
7
  gem 'byebug'
8
8
  end
9
+
10
+ group :test do
11
+ gem 'simplecov'
12
+ end
@@ -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
- Localeapp::CLI::Update.new(output: output_stream).execute
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
- Localeapp::CLI::Pull.new(output: output_stream).execute
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
@@ -1,5 +1,5 @@
1
1
  module Translator
2
2
  module Version
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.0.1'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,2 @@
1
+ en:
2
+ first_name: 'Kuldeep'
@@ -0,0 +1,2 @@
1
+ en:
2
+ last_name: 'Aggarwal'
@@ -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
@@ -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('localeapp', '~> 0.9')
26
- s.add_dependency('moneta', '~> 0.8')
27
- s.add_dependency('activesupport', '>= 3.2', '< 5')
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.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-22 00:00:00.000000000 Z
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: