lokalise_rails 1.4.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -0
  3. data/Gemfile +11 -0
  4. data/README.md +74 -54
  5. data/lib/generators/templates/lokalise_rails_config.rb +8 -4
  6. data/lib/lokalise_rails/global_config.rb +11 -0
  7. data/lib/lokalise_rails/utils.rb +20 -0
  8. data/lib/lokalise_rails/version.rb +3 -1
  9. data/lib/lokalise_rails.rb +4 -76
  10. data/lib/tasks/lokalise_rails_tasks.rake +6 -3
  11. data/lokalise_rails.gemspec +4 -16
  12. data/spec/dummy/config/lokalise_rails.rb +3 -3
  13. data/spec/lib/{lokalise_rails_spec.rb → lokalise_rails/global_config_spec.rb} +27 -5
  14. data/spec/lib/lokalise_rails/version_spec.rb +7 -0
  15. data/spec/lib/tasks/export_task_spec.rb +22 -15
  16. data/spec/lib/tasks/import_task_spec.rb +32 -97
  17. data/spec/lib/utils_spec.rb +16 -0
  18. data/spec/spec_helper.rb +0 -1
  19. data/spec/support/file_manager.rb +23 -20
  20. data/spec/support/spec_addons.rb +8 -3
  21. metadata +16 -185
  22. data/lib/lokalise_rails/error.rb +0 -10
  23. data/lib/lokalise_rails/task_definition/base.rb +0 -64
  24. data/lib/lokalise_rails/task_definition/exporter.rb +0 -73
  25. data/lib/lokalise_rails/task_definition/importer.rb +0 -108
  26. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -9
  27. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -8
  28. data/spec/dummy/config/initializers/content_security_policy.rb +0 -29
  29. data/spec/dummy/config/initializers/inflections.rb +0 -17
  30. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  31. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
  32. data/spec/lib/lokalise_rails/task_definition/base_spec.rb +0 -81
  33. data/spec/lib/lokalise_rails/task_definition/exporter_spec.rb +0 -160
  34. data/spec/lib/lokalise_rails/task_definition/importer_spec.rb +0 -54
@@ -1,121 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fileutils'
4
-
5
- RSpec.describe LokaliseRails do
6
- let(:loc_path) { described_class.locales_path }
7
- let(:local_trans) { "#{Rails.root}/public/trans.zip" }
8
- let(:remote_trans) { 'https://github.com/bodrovis/lokalise_rails/blob/master/spec/dummy/public/trans.zip?raw=true' }
3
+ RSpec.describe 'Import Rake task' do
4
+ let(:global_config) { LokaliseRails::GlobalConfig }
5
+ let(:loc_path) { global_config.locales_path }
9
6
 
10
7
  it 'halts when the API key is not set' do
11
- allow(described_class).to receive(:api_token).and_return(nil)
8
+ allow(global_config).to receive(:api_token).and_return(nil)
12
9
 
13
10
  expect(import_executor).to raise_error(SystemExit, /API token is not set/i)
14
- expect(described_class).to have_received(:api_token)
11
+ expect(global_config).to have_received(:api_token)
15
12
  end
16
13
 
17
14
  it 'halts when the project ID is not set' do
18
- allow_project_id nil do
19
- expect(import_executor).to raise_error(SystemExit, /ID is not set/i)
20
- end
21
- end
15
+ allow(global_config).to receive(:project_id).and_return(nil)
22
16
 
23
- context 'when directory is empty' do
24
- before do
25
- mkdir_locales
26
- rm_translation_files
27
- end
17
+ expect(import_executor).to raise_error(SystemExit, /ID is not set/i)
28
18
 
29
- after :all do
30
- rm_translation_files
31
- end
32
-
33
- it 'import rake task is callable' do
34
- allow(LokaliseRails::TaskDefinition::Importer).to receive(
35
- :download_files
36
- ).and_return(
37
- {
38
- 'project_id' => '123.abc',
39
- 'bundle_url' => local_trans
40
- }
41
- )
42
-
43
- expect(import_executor).to output(/complete!/).to_stdout
44
-
45
- expect(count_translations).to eq(4)
46
- expect(LokaliseRails::TaskDefinition::Importer).to have_received(:download_files)
47
- expect_file_exist loc_path, 'en/nested/main_en.yml'
48
- expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
49
- expect_file_exist loc_path, 'ru/main_ru.yml'
50
- end
51
-
52
- it 'import rake task downloads ZIP archive properly' do
53
- allow(LokaliseRails::TaskDefinition::Importer).to receive(
54
- :download_files
55
- ).and_return(
56
- {
57
- 'project_id' => '123.abc',
58
- 'bundle_url' => remote_trans
59
- }
60
- )
61
-
62
- expect(import_executor).to output(/complete!/).to_stdout
63
-
64
- expect(LokaliseRails::TaskDefinition::Importer).to have_received(:download_files)
65
- expect(count_translations).to eq(4)
66
- expect_file_exist loc_path, 'en/nested/main_en.yml'
67
- expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
68
- expect_file_exist loc_path, 'ru/main_ru.yml'
69
- end
19
+ expect(global_config).to have_received(:project_id)
70
20
  end
71
21
 
72
- context 'when directory is not empty and safe mode enabled' do
73
- before :all do
74
- mkdir_locales
75
- described_class.import_safe_mode = true
76
- end
77
-
22
+ context 'when directory is empty' do
78
23
  before do
24
+ mkdir_locales
79
25
  rm_translation_files
80
- add_translation_files!
81
26
  end
82
27
 
83
28
  after :all do
84
29
  rm_translation_files
85
- described_class.import_safe_mode = false
86
30
  end
87
31
 
88
- it 'import proceeds when the user agrees' do
89
- allow(LokaliseRails::TaskDefinition::Importer).to receive(
90
- :download_files
91
- ).and_return(
92
- {
93
- 'project_id' => '123.abc',
94
- 'bundle_url' => local_trans
95
- }
96
- )
97
-
98
- allow($stdin).to receive(:gets).and_return('Y')
99
- expect(import_executor).to output(/is not empty/).to_stdout
100
-
101
- expect(count_translations).to eq(5)
102
- expect($stdin).to have_received(:gets)
103
- expect(LokaliseRails::TaskDefinition::Importer).to have_received(:download_files)
104
- expect_file_exist loc_path, 'en/nested/main_en.yml'
105
- expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
106
- expect_file_exist loc_path, 'ru/main_ru.yml'
107
- end
108
-
109
- it 'import halts when a user chooses not to proceed' do
110
- allow(LokaliseRails::TaskDefinition::Importer).to receive(
111
- :download_files
112
- ).at_most(0).times
113
- allow($stdin).to receive(:gets).and_return('N')
114
- expect(import_executor).to output(/is not empty/).to_stdout
115
-
116
- expect(LokaliseRails::TaskDefinition::Importer).not_to have_received(:download_files)
117
- expect($stdin).to have_received(:gets)
118
- expect(count_translations).to eq(1)
32
+ describe 'import' do
33
+ it 'is callable' do
34
+ allow_project_id global_config, ENV['LOKALISE_PROJECT_ID'] do
35
+ VCR.use_cassette('download_files') do
36
+ expect(import_executor).to output(/complete!/).to_stdout
37
+ end
38
+
39
+ expect(count_translations).to eq(4)
40
+
41
+ expect_file_exist loc_path, 'en.yml'
42
+ expect_file_exist loc_path, 'ru.yml'
43
+ expect_file_exist loc_path, 'yo.yml'
44
+ end
45
+ end
46
+
47
+ it 're-raises export errors' do
48
+ allow_project_id global_config, 'fake' do
49
+ VCR.use_cassette('download_files_error') do
50
+ expect(import_executor).to raise_error(SystemExit, /Invalid `project_id` parameter/)
51
+ end
52
+ end
53
+ end
119
54
  end
120
55
  end
121
56
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe LokaliseRails::Utils do
4
+ describe '.rails_root' do
5
+ it 'returns RAILS_ROOT if defined' do
6
+ allow(::Rails).to receive(:root).and_return(nil)
7
+ stub_const('RAILS_ROOT', '/stub')
8
+ expect(described_class.rails_root).to eq('/stub')
9
+ end
10
+
11
+ it 'fallbacks if neither roots are present' do
12
+ allow(::Rails).to receive(:root).and_return(nil)
13
+ expect(described_class.rails_root).to be_nil
14
+ end
15
+ end
16
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,6 @@ SimpleCov.start 'rails' do
7
7
  add_filter 'spec/'
8
8
  add_filter '.github/'
9
9
  add_filter 'lib/generators/templates/'
10
- add_filter 'lib/lokalise_rails/version'
11
10
  end
12
11
 
13
12
  if ENV['CI'] == 'true'
@@ -3,13 +3,8 @@
3
3
  require 'fileutils'
4
4
 
5
5
  module FileManager
6
- def expect_file_exist(path, file)
7
- file_path = File.join path, file
8
- expect(File.file?(file_path)).to be true
9
- end
10
-
11
6
  def mkdir_locales
12
- FileUtils.mkdir_p(LokaliseRails.locales_path) unless File.directory?(LokaliseRails.locales_path)
7
+ FileUtils.mkdir_p(LokaliseRails::GlobalConfig.locales_path) unless File.directory?(LokaliseRails::GlobalConfig.locales_path)
13
8
  end
14
9
 
15
10
  def rm_translation_files
@@ -17,38 +12,46 @@ module FileManager
17
12
  end
18
13
 
19
14
  def locales_dir
20
- Dir["#{LokaliseRails.locales_path}/**/*"]
15
+ Dir["#{LokaliseRails::GlobalConfig.locales_path}/**/*"]
21
16
  end
22
17
 
23
18
  def count_translations
24
19
  locales_dir.count { |file| File.file?(file) }
25
20
  end
26
21
 
27
- def add_translation_files!(with_ru: false)
22
+ def add_translation_files!(with_ru: false, additional: nil)
28
23
  FileUtils.mkdir_p "#{Rails.root}/config/locales/nested"
29
- File.open("#{Rails.root}/config/locales/nested/en.yml", 'w+:UTF-8') do |f|
30
- f.write en_data
31
- end
24
+ open_and_write('config/locales/nested/en.yml') { |f| f.write en_data }
32
25
 
33
26
  return unless with_ru
34
27
 
35
- File.open("#{Rails.root}/config/locales/ru.yml", 'w+:UTF-8') do |f|
36
- f.write ru_data
28
+ open_and_write('config/locales/ru.yml') { |f| f.write ru_data }
29
+
30
+ return unless additional
31
+
32
+ additional.times do |i|
33
+ data = {'en' => {"key_#{i}" => "value #{i}"}}
34
+
35
+ open_and_write("config/locales/en_#{i}.yml") { |f| f.write data.to_yaml }
37
36
  end
38
37
  end
39
38
 
40
- def add_config!
39
+ def add_config!(custom_text = '')
41
40
  data = <<~DATA
42
- require 'lokalise_rails'
43
- LokaliseRails.config do |c|
41
+ LokaliseRails::GlobalConfig.config do |c|
44
42
  c.api_token = ENV['LOKALISE_API_TOKEN']
45
43
  c.project_id = ENV['LOKALISE_PROJECT_ID']
46
- end
47
44
  DATA
48
45
 
49
- File.open("#{Rails.root}/config/lokalise_rails.rb", 'w+:UTF-8') do |f|
50
- f.write data
51
- end
46
+ data += custom_text
47
+ data += "\nend"
48
+ open_and_write('config/lokalise_rails.rb') { |f| f.write data }
49
+ end
50
+
51
+ def open_and_write(rel_path, &block)
52
+ return unless block
53
+
54
+ File.open("#{Rails.root}/#{rel_path}", 'w+:UTF-8', &block)
52
55
  end
53
56
 
54
57
  def remove_config
@@ -1,11 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SpecAddons
4
- def allow_project_id(value = ENV['LOKALISE_PROJECT_ID'])
5
- allow(LokaliseRails).to receive(:project_id).and_return(value)
4
+ def expect_file_exist(path, file)
5
+ file_path = File.join path, file
6
+ expect(File.file?(file_path)).to be true
7
+ end
8
+
9
+ def allow_project_id(obj, value)
10
+ allow(obj).to receive(:project_id).and_return(value)
6
11
  return unless block_given?
7
12
 
8
13
  yield
9
- expect(LokaliseRails).to have_received(:project_id)
14
+ expect(obj).to have_received(:project_id)
10
15
  end
11
16
  end
metadata CHANGED
@@ -1,183 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lokalise_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 4.0.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-07-29 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ruby-lokalise-api
14
+ name: lokalise_manager
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rubyzip
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.3'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.3'
41
- - !ruby/object:Gem::Dependency
42
- name: codecov
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.2'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.2'
55
- - !ruby/object:Gem::Dependency
56
- name: dotenv
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.5'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.5'
69
- - !ruby/object:Gem::Dependency
70
- name: rails
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 6.1.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 6.1.0
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '13.0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '13.0'
97
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.6'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.6'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '1.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '1.0'
125
- - !ruby/object:Gem::Dependency
126
- name: rubocop-performance
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '1.5'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '1.5'
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop-rspec
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: 2.4.0
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: 2.4.0
153
- - !ruby/object:Gem::Dependency
154
- name: simplecov
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.16'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '0.16'
167
- - !ruby/object:Gem::Dependency
168
- name: vcr
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '6.0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '6.0'
26
+ version: '2.0'
181
27
  description: This gem allows to exchange translation files between your Rails app
182
28
  and Lokalise TMS.
183
29
  email:
@@ -198,11 +44,9 @@ files:
198
44
  - lib/generators/lokalise_rails/install_generator.rb
199
45
  - lib/generators/templates/lokalise_rails_config.rb
200
46
  - lib/lokalise_rails.rb
201
- - lib/lokalise_rails/error.rb
47
+ - lib/lokalise_rails/global_config.rb
202
48
  - lib/lokalise_rails/railtie.rb
203
- - lib/lokalise_rails/task_definition/base.rb
204
- - lib/lokalise_rails/task_definition/exporter.rb
205
- - lib/lokalise_rails/task_definition/importer.rb
49
+ - lib/lokalise_rails/utils.rb
206
50
  - lib/lokalise_rails/version.rb
207
51
  - lib/tasks/lokalise_rails_tasks.rake
208
52
  - lokalise_rails.gemspec
@@ -215,26 +59,19 @@ files:
215
59
  - spec/dummy/config/environments/development.rb
216
60
  - spec/dummy/config/environments/production.rb
217
61
  - spec/dummy/config/environments/test.rb
218
- - spec/dummy/config/initializers/application_controller_renderer.rb
219
62
  - spec/dummy/config/initializers/assets.rb
220
- - spec/dummy/config/initializers/backtrace_silencers.rb
221
- - spec/dummy/config/initializers/content_security_policy.rb
222
63
  - spec/dummy/config/initializers/cookies_serializer.rb
223
64
  - spec/dummy/config/initializers/filter_parameter_logging.rb
224
- - spec/dummy/config/initializers/inflections.rb
225
- - spec/dummy/config/initializers/mime_types.rb
226
- - spec/dummy/config/initializers/wrap_parameters.rb
227
65
  - spec/dummy/config/lokalise_rails.rb
228
66
  - spec/dummy/config/puma.rb
229
67
  - spec/dummy/config/routes.rb
230
68
  - spec/dummy/db/seeds.rb
231
69
  - spec/lib/generators/lokalise_rails/install_generator_spec.rb
232
- - spec/lib/lokalise_rails/task_definition/base_spec.rb
233
- - spec/lib/lokalise_rails/task_definition/exporter_spec.rb
234
- - spec/lib/lokalise_rails/task_definition/importer_spec.rb
235
- - spec/lib/lokalise_rails_spec.rb
70
+ - spec/lib/lokalise_rails/global_config_spec.rb
71
+ - spec/lib/lokalise_rails/version_spec.rb
236
72
  - spec/lib/tasks/export_task_spec.rb
237
73
  - spec/lib/tasks/import_task_spec.rb
74
+ - spec/lib/utils_spec.rb
238
75
  - spec/spec_helper.rb
239
76
  - spec/support/file_manager.rb
240
77
  - spec/support/rake_utils.rb
@@ -243,7 +80,8 @@ files:
243
80
  homepage: https://github.com/bodrovis/lokalise_rails
244
81
  licenses:
245
82
  - MIT
246
- metadata: {}
83
+ metadata:
84
+ rubygems_mfa_required: 'true'
247
85
  post_install_message:
248
86
  rdoc_options: []
249
87
  require_paths:
@@ -259,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
97
  - !ruby/object:Gem::Version
260
98
  version: '0'
261
99
  requirements: []
262
- rubygems_version: 3.2.24
100
+ rubygems_version: 3.3.5
263
101
  signing_key:
264
102
  specification_version: 4
265
103
  summary: Lokalise integration for Ruby on Rails
@@ -273,26 +111,19 @@ test_files:
273
111
  - spec/dummy/config/environments/development.rb
274
112
  - spec/dummy/config/environments/production.rb
275
113
  - spec/dummy/config/environments/test.rb
276
- - spec/dummy/config/initializers/application_controller_renderer.rb
277
114
  - spec/dummy/config/initializers/assets.rb
278
- - spec/dummy/config/initializers/backtrace_silencers.rb
279
- - spec/dummy/config/initializers/content_security_policy.rb
280
115
  - spec/dummy/config/initializers/cookies_serializer.rb
281
116
  - spec/dummy/config/initializers/filter_parameter_logging.rb
282
- - spec/dummy/config/initializers/inflections.rb
283
- - spec/dummy/config/initializers/mime_types.rb
284
- - spec/dummy/config/initializers/wrap_parameters.rb
285
117
  - spec/dummy/config/lokalise_rails.rb
286
118
  - spec/dummy/config/puma.rb
287
119
  - spec/dummy/config/routes.rb
288
120
  - spec/dummy/db/seeds.rb
289
121
  - spec/lib/generators/lokalise_rails/install_generator_spec.rb
290
- - spec/lib/lokalise_rails/task_definition/base_spec.rb
291
- - spec/lib/lokalise_rails/task_definition/exporter_spec.rb
292
- - spec/lib/lokalise_rails/task_definition/importer_spec.rb
293
- - spec/lib/lokalise_rails_spec.rb
122
+ - spec/lib/lokalise_rails/global_config_spec.rb
123
+ - spec/lib/lokalise_rails/version_spec.rb
294
124
  - spec/lib/tasks/export_task_spec.rb
295
125
  - spec/lib/tasks/import_task_spec.rb
126
+ - spec/lib/utils_spec.rb
296
127
  - spec/spec_helper.rb
297
128
  - spec/support/file_manager.rb
298
129
  - spec/support/rake_utils.rb
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LokaliseRails
4
- class Error < StandardError
5
- # Initializes a new Error object
6
- def initialize(message = '')
7
- super(message)
8
- end
9
- end
10
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ruby-lokalise-api'
4
- require 'pathname'
5
-
6
- module LokaliseRails
7
- module TaskDefinition
8
- class Base
9
- class << self
10
- attr_writer :api_client
11
-
12
- # Creates a Lokalise API client
13
- #
14
- # @return [Lokalise::Client]
15
- def api_client
16
- @api_client ||= ::Lokalise.client LokaliseRails.api_token, LokaliseRails.timeouts
17
- end
18
-
19
- # Resets API client
20
- def reset_api_client!
21
- Lokalise.reset_client!
22
- @api_client = nil
23
- end
24
-
25
- # Checks task options
26
- #
27
- # @return Array
28
- def check_options_errors!
29
- errors = []
30
- errors << 'Project ID is not set!' if LokaliseRails.project_id.nil? || LokaliseRails.project_id.empty?
31
- errors << 'Lokalise API token is not set!' if LokaliseRails.api_token.nil? || LokaliseRails.api_token.empty?
32
-
33
- raise(LokaliseRails::Error, errors.join(' ')) if errors.any?
34
- end
35
-
36
- private
37
-
38
- # Checks whether the provided file has a proper extension as dictated by the `file_ext_regexp` option
39
- #
40
- # @return Boolean
41
- # @param raw_path [String, Pathname]
42
- def proper_ext?(raw_path)
43
- path = raw_path.is_a?(Pathname) ? raw_path : Pathname.new(raw_path)
44
- LokaliseRails.file_ext_regexp.match? path.extname
45
- end
46
-
47
- # Returns directory and filename for the given entry
48
- #
49
- # @return Array
50
- # @param entry [String]
51
- def subdir_and_filename_for(entry)
52
- Pathname.new(entry).split
53
- end
54
-
55
- # Returns Lokalise project ID and branch, semicolumn separated
56
- #
57
- # @return [String]
58
- def project_id_with_branch
59
- "#{LokaliseRails.project_id}:#{LokaliseRails.branch}"
60
- end
61
- end
62
- end
63
- end
64
- end