lokalise_manager 1.1.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6dbbda54dc255ed4ec13547b954213e41ab38c90d1520ffe3762d36dc2917f8
4
- data.tar.gz: a341a91e4fea6ff76e0de87e5efa9660f5a0c5a7659656fbcfa14600fc4937d8
3
+ metadata.gz: 49d525043d80bf4643208f1de37d06bdd12826c04b01cbde07ae566e5ab1e056
4
+ data.tar.gz: a3f7ea97ae346b93220677342e771f2e916112572d4c54c779664c7a0651f2b3
5
5
  SHA512:
6
- metadata.gz: 2f5f277f431596f70ee52f45186a972dcd507d1be08f6fc71bd04117556ca803efbe3e8b0d6a123ec6f81b959a5a1c99d9aa63a3189a4700a195fb823ca766e2
7
- data.tar.gz: c64848ee98ee90cd77507bae719048ac425c60b7f16581b52de6ed6ab2301976487f6999027eab729244c4d3e8b27af1d5d6875c74d8b3d7cbd35112e0ededf1
6
+ metadata.gz: 59b08352f934330e07762d73066afadcb440478ef3548686b1ef32ab6ae3a0fb645a4da55cb7c75c02ff42d49ea73c82728f8247a6e78531de1154c40573f002
7
+ data.tar.gz: 98337218aa0519ab6d2982b38ce7582276301692c6cde59f5d2d75039a1951b1d8b7769584d6884ae3994286998299826cedadd8eba9ae3a5f65d87a1a9dabc9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 (26-Oct-21)
4
+
5
+ * Add a new option `:silent_mode` which is `false` by default. When silent mode is enabled, no debug info will be printed out to `$stdout`. The only exception are the "safe mode" messages — you'll still be prompted to continue if the target directory is not empty.
6
+ * Use `#deep_merge` instead of a simple merge when processing options.
7
+
3
8
  ## 1.1.0 (25-Oct-21)
4
9
 
5
10
  * Add a new option `:use_oauth2_token` which is `false` by default. When enabled, you'll be able to provide a token obtained via [OAuth 2 flow](https://docs.lokalise.com/en/articles/5574713-oauth-2) rather than generated via Lokalise profile. The token should still be provided via the `:api_token` option:
data/README.md CHANGED
@@ -15,6 +15,8 @@ If you are looking for a Rails integration, please check [lokalise_rails](https:
15
15
 
16
16
  This gem requires Ruby 2.5+. You will also need to [setup a Lokalise account](https://app.lokalise.com/signup) and create a [translation project](https://docs.lokalise.com/en/articles/1400460-projects). Finally, you will need to generate a [read/write API token](https://docs.lokalise.com/en/articles/1929556-api-tokens) at your Lokalise profile.
17
17
 
18
+ Alternatively, you can utilize a token obtained via OAuth 2 flow. When using such a token, you'll have to set `:use_oauth2_token` option to `true` (see below).
19
+
18
20
  ### Installation
19
21
 
20
22
  Add the gem to your `Gemfile`:
@@ -92,6 +94,7 @@ Please don't forget that Lokalise API has rate limiting and you cannot send more
92
94
  * `locales_path` (`string`) — path to the directory with your translation files. Defaults to `"#{Dir.getwd}/locales"`.
93
95
  * `branch` (`string`) — Lokalise project branch to use. Defaults to `""` (no branch is provided).
94
96
  * `timeouts` (`hash`) — set [request timeouts for the Lokalise API client](https://lokalise.github.io/ruby-lokalise-api/additional_info/customization#setting-timeouts). By default, requests have no timeouts: `{open_timeout: nil, timeout: nil}`. Both values are in seconds.
97
+ * `silent_mode` (`boolean`) — whether you would like to output debugging information to `$stdout`. By default, after a task is performed, a short notification message will be printed out to the terminal. When set to `false`, notifications won't be printed. Please note that currently `import_safe_mode` has higher priority. Even if you enable `silent_mode`, and the `import_safe_mode` is enabled as well, you will be prompted to confirm the import operation if the target directory is not empty.
95
98
 
96
99
  ### Import config
97
100
 
data/lib/ext/hash.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Taken from https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
4
+
5
+ class Hash
6
+ def deep_merge(other_hash, &block)
7
+ dup.deep_merge!(other_hash, &block)
8
+ end
9
+
10
+ # Same as +deep_merge+, but modifies +self+.
11
+ def deep_merge!(other_hash, &block)
12
+ merge!(other_hash) do |key, this_val, other_val|
13
+ if this_val.is_a?(Hash) && other_val.is_a?(Hash)
14
+ this_val.deep_merge(other_val, &block)
15
+ elsif block
16
+ yield(key, this_val, other_val)
17
+ else
18
+ other_val
19
+ end
20
+ end
21
+ end
22
+ end
@@ -7,13 +7,18 @@ module LokaliseManager
7
7
  attr_writer :import_opts, :import_safe_mode, :export_opts, :locales_path,
8
8
  :file_ext_regexp, :skip_file_export, :branch, :timeouts,
9
9
  :translations_loader, :translations_converter, :lang_iso_inferer,
10
- :max_retries_export, :max_retries_import, :use_oauth2_token
10
+ :max_retries_export, :max_retries_import, :use_oauth2_token, :silent_mode
11
11
 
12
12
  # Main interface to provide configuration options
13
13
  def config
14
14
  yield self
15
15
  end
16
16
 
17
+ # When enabled, won't print any debugging info to $stdout
18
+ def silent_mode
19
+ @silent_mode || false
20
+ end
21
+
17
22
  # When enabled, will use OAuth 2 Lokalise client and will require to provide a token obtained via OAuth 2 flow
18
23
  # rather than via Lokalise profile
19
24
  def use_oauth2_token
@@ -23,7 +23,7 @@ module LokaliseManager
23
23
  opts[reader.to_sym] = global_config.send(reader)
24
24
  end
25
25
 
26
- @config = OpenStruct.new primary_opts.merge(custom_opts)
26
+ @config = OpenStruct.new primary_opts.deep_merge(custom_opts)
27
27
  end
28
28
 
29
29
  # Creates a Lokalise API client
@@ -18,7 +18,7 @@ module LokaliseManager
18
18
  raise e.class, "Error while trying to upload #{full_path}: #{e.message}"
19
19
  end
20
20
 
21
- $stdout.print 'Task complete!'
21
+ $stdout.print('Task complete!') unless config.silent_mode
22
22
 
23
23
  queued_processes
24
24
  end
@@ -14,13 +14,13 @@ module LokaliseManager
14
14
  check_options_errors!
15
15
 
16
16
  unless proceed_when_safe_mode?
17
- $stdout.print 'Task cancelled!'
17
+ $stdout.print('Task cancelled!') unless config.silent_mode
18
18
  return false
19
19
  end
20
20
 
21
21
  open_and_process_zip download_files['bundle_url']
22
22
 
23
- $stdout.print 'Task complete!'
23
+ $stdout.print('Task complete!') unless config.silent_mode
24
24
  true
25
25
  end
26
26
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LokaliseManager
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
+ require 'ext/hash'
6
+
5
7
  require 'lokalise_manager/version'
6
8
  require 'lokalise_manager/error'
7
9
  require 'lokalise_manager/global_config'
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Hash do
4
+ let(:h1) { {a: 100, b: 200, c: {c1: 100}} }
5
+ let(:h2) { {b: 250, c: {c1: 200}} }
6
+
7
+ specify '#deep_merge' do
8
+ result = h1.deep_merge(h2) { |_key, this_val, other_val| this_val + other_val }
9
+ expect(result[:b]).to eq(450)
10
+ expect(result[:c][:c1]).to eq(300)
11
+ end
12
+ end
@@ -14,6 +14,11 @@ describe LokaliseManager::GlobalConfig do
14
14
  fake_class.project_id = '123.abc'
15
15
  end
16
16
 
17
+ it 'is possible to set silent_mode' do
18
+ allow(fake_class).to receive(:silent_mode=).with(true)
19
+ fake_class.silent_mode = true
20
+ end
21
+
17
22
  it 'is possible to set use_oauth2_token' do
18
23
  allow(fake_class).to receive(:use_oauth2_token=).with(true)
19
24
  fake_class.use_oauth2_token = true
@@ -19,6 +19,11 @@ describe LokaliseManager::TaskDefinitions::Base do
19
19
  expect(obj.config.project_id).to eq('345')
20
20
  expect(obj.config.token).to eq('fake')
21
21
  end
22
+
23
+ it 'tes' do
24
+ obj = described_class.new import_opts: {filter_langs: ['fr']}
25
+ puts obj.config
26
+ end
22
27
  end
23
28
 
24
29
  specify '.reset_client!' do
@@ -24,9 +24,11 @@ describe LokaliseManager::TaskDefinitions::Exporter do
24
24
 
25
25
  describe '.export!' do
26
26
  it 'sends a proper API request and handles rate limiting' do
27
- process = VCR.use_cassette('upload_files_multiple') do
28
- described_object.export!
29
- end.first
27
+ process = nil
28
+
29
+ VCR.use_cassette('upload_files_multiple') do
30
+ expect(-> { process = described_object.export!.first }).to output(/complete!/).to_stdout
31
+ end
30
32
 
31
33
  expect(process.project_id).to eq(project_id)
32
34
  expect(process.status).to eq('queued')
@@ -58,6 +60,19 @@ describe LokaliseManager::TaskDefinitions::Exporter do
58
60
  end
59
61
 
60
62
  describe '.export!' do
63
+ it 'sends a proper API request but does not output anything when silent_mode is enabled' do
64
+ allow(described_object.config).to receive(:silent_mode).and_return(true)
65
+
66
+ process = nil
67
+
68
+ VCR.use_cassette('upload_files') do
69
+ expect(-> { process = described_object.export!.first }).not_to output(/complete!/).to_stdout
70
+ end
71
+
72
+ expect(process.status).to eq('queued')
73
+ expect(described_object.config).to have_received(:silent_mode).at_most(1).times
74
+ end
75
+
61
76
  it 'sends a proper API request' do
62
77
  process = VCR.use_cassette('upload_files') do
63
78
  described_object.export!
@@ -103,8 +103,10 @@ describe LokaliseManager::TaskDefinitions::Importer do
103
103
  end
104
104
 
105
105
  it 'runs import successfully' do
106
- result = VCR.use_cassette('import') do
107
- described_object.import!
106
+ result = nil
107
+
108
+ VCR.use_cassette('import') do
109
+ expect(-> { result = described_object.import! }).to output(/complete!/).to_stdout
108
110
  end
109
111
 
110
112
  expect(result).to be true
@@ -113,6 +115,20 @@ describe LokaliseManager::TaskDefinitions::Importer do
113
115
  expect_file_exist loc_path, 'en.yml'
114
116
  expect_file_exist loc_path, 'ru.yml'
115
117
  end
118
+
119
+ it 'runs import successfully but does not provide any output when silent_mode is enabled' do
120
+ allow(described_object.config).to receive(:silent_mode).and_return(true)
121
+ result = nil
122
+
123
+ VCR.use_cassette('import') do
124
+ expect(-> { result = described_object.import! }).not_to output(/complete!/).to_stdout
125
+ end
126
+
127
+ expect(result).to be true
128
+ expect_file_exist loc_path, 'en.yml'
129
+ expect_file_exist loc_path, 'ru.yml'
130
+ expect(described_object.config).to have_received(:silent_mode).at_most(1).times
131
+ end
116
132
  end
117
133
 
118
134
  context 'when directory is not empty and safe mode enabled' do
@@ -157,9 +173,21 @@ describe LokaliseManager::TaskDefinitions::Importer do
157
173
  it 'import halts when a user chooses not to proceed' do
158
174
  allow(safe_mode_obj).to receive(:download_files).at_most(0).times
159
175
  allow($stdin).to receive(:gets).and_return('N')
160
- expect(-> { safe_mode_obj.import! }).to output(/is not empty/).to_stdout
176
+ expect(-> { safe_mode_obj.import! }).to output(/cancelled/).to_stdout
177
+
178
+ expect(safe_mode_obj).not_to have_received(:download_files)
179
+ expect($stdin).to have_received(:gets)
180
+ expect(count_translations).to eq(1)
181
+ end
182
+
183
+ it 'import halts when a user chooses not to proceed and debug info is not printed out when silent_mode is enabled' do
184
+ allow(safe_mode_obj.config).to receive(:silent_mode).and_return(true)
185
+ allow(safe_mode_obj).to receive(:download_files).at_most(0).times
186
+ allow($stdin).to receive(:gets).and_return('N')
187
+ expect(-> { safe_mode_obj.import! }).not_to output(/cancelled/).to_stdout
161
188
 
162
189
  expect(safe_mode_obj).not_to have_received(:download_files)
190
+ expect(safe_mode_obj.config).to have_received(:silent_mode)
163
191
  expect($stdin).to have_received(:gets)
164
192
  expect(count_translations).to eq(1)
165
193
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lokalise_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-25 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-lokalise-api
@@ -181,6 +181,7 @@ files:
181
181
  - LICENSE
182
182
  - README.md
183
183
  - Rakefile
184
+ - lib/ext/hash.rb
184
185
  - lib/lokalise_manager.rb
185
186
  - lib/lokalise_manager/error.rb
186
187
  - lib/lokalise_manager/global_config.rb
@@ -189,6 +190,7 @@ files:
189
190
  - lib/lokalise_manager/task_definitions/importer.rb
190
191
  - lib/lokalise_manager/version.rb
191
192
  - lokalise_manager.gemspec
193
+ - spec/lib/ext/hash_spec.rb
192
194
  - spec/lib/lokalise_manager/global_config_spec.rb
193
195
  - spec/lib/lokalise_manager/task_definitions/base_spec.rb
194
196
  - spec/lib/lokalise_manager/task_definitions/exporter_spec.rb
@@ -217,11 +219,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
219
  - !ruby/object:Gem::Version
218
220
  version: '0'
219
221
  requirements: []
220
- rubygems_version: 3.2.26
222
+ rubygems_version: 3.2.29
221
223
  signing_key:
222
224
  specification_version: 4
223
225
  summary: Lokalise integration for Ruby
224
226
  test_files:
227
+ - spec/lib/ext/hash_spec.rb
225
228
  - spec/lib/lokalise_manager/global_config_spec.rb
226
229
  - spec/lib/lokalise_manager/task_definitions/base_spec.rb
227
230
  - spec/lib/lokalise_manager/task_definitions/exporter_spec.rb