lokalise_rails 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/README.md +71 -56
- data/lib/generators/templates/lokalise_rails_config.rb +2 -4
- data/lib/lokalise_rails/global_config.rb +11 -0
- data/lib/lokalise_rails/utils.rb +20 -0
- data/lib/lokalise_rails/version.rb +1 -1
- data/lib/lokalise_rails.rb +4 -87
- data/lib/tasks/lokalise_rails_tasks.rake +6 -3
- data/lokalise_rails.gemspec +3 -4
- data/spec/dummy/config/lokalise_rails.rb +3 -3
- data/spec/lib/lokalise_rails/global_config_spec.rb +117 -0
- data/spec/lib/lokalise_rails_spec.rb +0 -98
- data/spec/lib/tasks/export_task_spec.rb +22 -15
- data/spec/lib/tasks/import_task_spec.rb +32 -95
- data/spec/lib/utils_spec.rb +16 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/support/file_manager.rb +6 -11
- data/spec/support/spec_addons.rb +8 -3
- metadata +16 -34
- data/lib/lokalise_rails/error.rb +0 -10
- data/lib/lokalise_rails/task_definition/base.rb +0 -80
- data/lib/lokalise_rails/task_definition/exporter.rb +0 -79
- data/lib/lokalise_rails/task_definition/importer.rb +0 -109
- data/spec/lib/lokalise_rails/task_definition/base_spec.rb +0 -81
- data/spec/lib/lokalise_rails/task_definition/exporter_spec.rb +0 -200
- data/spec/lib/lokalise_rails/task_definition/importer_spec.rb +0 -72
@@ -4,102 +4,4 @@ describe LokaliseRails do
|
|
4
4
|
it 'returns a proper version' do
|
5
5
|
expect(LokaliseRails::VERSION).to be_a(String)
|
6
6
|
end
|
7
|
-
|
8
|
-
it 'is possible to provide config options' do
|
9
|
-
described_class.config do |c|
|
10
|
-
expect(c).to eq(described_class)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'parameters' do
|
15
|
-
let(:fake_class) { class_double('LokaliseRails') }
|
16
|
-
|
17
|
-
it 'is possible to set project_id' do
|
18
|
-
allow(fake_class).to receive(:project_id=).with('123.abc')
|
19
|
-
fake_class.project_id = '123.abc'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'is possible to set file_ext_regexp' do
|
23
|
-
allow(fake_class).to receive(:file_ext_regexp=).with(Regexp.new('.*'))
|
24
|
-
fake_class.file_ext_regexp = Regexp.new('.*')
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'is possible to set import_opts' do
|
28
|
-
allow(fake_class).to receive(:import_opts=).with(duck_type(:each))
|
29
|
-
fake_class.import_opts = {
|
30
|
-
format: 'json',
|
31
|
-
indentation: '8sp'
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'is possible to set export_opts' do
|
36
|
-
allow(fake_class).to receive(:export_opts=).with(duck_type(:each))
|
37
|
-
fake_class.export_opts = {
|
38
|
-
convert_placeholders: true,
|
39
|
-
detect_icu_plurals: true
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'is possible to set branch' do
|
44
|
-
allow(fake_class).to receive(:branch=).with('custom')
|
45
|
-
fake_class.branch = 'custom'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'is possible to set timeouts' do
|
49
|
-
allow(fake_class).to receive(:timeouts=).with(duck_type(:each))
|
50
|
-
fake_class.timeouts = {
|
51
|
-
open_timeout: 100,
|
52
|
-
timeout: 500
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'is possible to set import_safe_mode' do
|
57
|
-
allow(fake_class).to receive(:import_safe_mode=).with(true)
|
58
|
-
fake_class.import_safe_mode = true
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'is possible to set max_retries_export' do
|
62
|
-
allow(fake_class).to receive(:max_retries_export=).with(10)
|
63
|
-
fake_class.max_retries_export = 10
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'is possible to set max_retries_import' do
|
67
|
-
allow(fake_class).to receive(:max_retries_import=).with(10)
|
68
|
-
fake_class.max_retries_import = 10
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'is possible to set api_token' do
|
72
|
-
allow(fake_class).to receive(:api_token=).with('abc')
|
73
|
-
fake_class.api_token = 'abc'
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'is possible to override locales_path' do
|
77
|
-
allow(fake_class).to receive(:locales_path=).with('/demo/path')
|
78
|
-
fake_class.locales_path = '/demo/path'
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'is possible to set skip_file_export' do
|
82
|
-
cond = ->(f) { f.nil? }
|
83
|
-
allow(fake_class).to receive(:skip_file_export=).with(cond)
|
84
|
-
fake_class.skip_file_export = cond
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'is possible to set translations_loader' do
|
88
|
-
runner = ->(f) { f.to_json }
|
89
|
-
allow(fake_class).to receive(:translations_loader=).with(runner)
|
90
|
-
fake_class.translations_loader = runner
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'is possible to set translations_converter' do
|
94
|
-
runner = ->(f) { f.to_json }
|
95
|
-
allow(fake_class).to receive(:translations_converter=).with(runner)
|
96
|
-
fake_class.translations_converter = runner
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'is possible to set lang_iso_inferer' do
|
100
|
-
runner = ->(f) { f.to_json }
|
101
|
-
allow(fake_class).to receive(:lang_iso_inferer=).with(runner)
|
102
|
-
fake_class.lang_iso_inferer = runner
|
103
|
-
end
|
104
|
-
end
|
105
7
|
end
|
@@ -1,27 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe
|
3
|
+
RSpec.describe 'Export Rake task' do
|
4
|
+
let(:global_config) { LokaliseRails::GlobalConfig }
|
5
|
+
|
4
6
|
it 'halts when the API key is not set' do
|
5
|
-
allow(
|
7
|
+
allow(global_config).to receive(:api_token).and_return(nil)
|
6
8
|
|
7
9
|
expect(export_executor).to raise_error(SystemExit, /API token is not set/i)
|
8
|
-
expect(
|
10
|
+
expect(global_config).to have_received(:api_token)
|
9
11
|
end
|
10
12
|
|
11
13
|
it 'halts when the project ID is not set' do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
14
|
+
allow(global_config).to receive(:project_id).and_return(nil)
|
15
|
+
|
16
|
+
expect(export_executor).to raise_error(SystemExit, /ID is not set/i)
|
16
17
|
|
17
|
-
|
18
|
-
expect(export_executor).to output(/complete!/).to_stdout
|
18
|
+
expect(global_config).to have_received(:project_id)
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'with two translation files' do
|
22
22
|
let(:filename_ru) { 'ru.yml' }
|
23
23
|
let(:path_ru) { "#{Rails.root}/config/locales/#{filename_ru}" }
|
24
|
-
let(:relative_name_ru) { filename_ru }
|
25
24
|
|
26
25
|
before :all do
|
27
26
|
add_translation_files! with_ru: true
|
@@ -31,12 +30,20 @@ RSpec.describe LokaliseRails do
|
|
31
30
|
rm_translation_files
|
32
31
|
end
|
33
32
|
|
34
|
-
describe '
|
35
|
-
it '
|
36
|
-
allow_project_id
|
33
|
+
describe 'export' do
|
34
|
+
it 'is callable' do
|
35
|
+
allow_project_id global_config, ENV['LOKALISE_PROJECT_ID'] do
|
36
|
+
VCR.use_cassette('upload_files') do
|
37
|
+
expect(export_executor).to output(/complete!/).to_stdout
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
37
41
|
|
38
|
-
|
39
|
-
|
42
|
+
it 're-raises export errors' do
|
43
|
+
allow_project_id global_config, '542886116159f798720dc4.94769464' do
|
44
|
+
VCR.use_cassette('upload_files_error') do
|
45
|
+
expect(export_executor).to raise_error(SystemExit, /Unknown `lang_iso`/)
|
46
|
+
end
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
@@ -2,120 +2,57 @@
|
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
|
-
RSpec.describe
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:remote_trans) { 'https://github.com/bodrovis/lokalise_rails/blob/master/spec/dummy/public/trans.zip?raw=true' }
|
5
|
+
RSpec.describe 'Import Rake task' do
|
6
|
+
let(:global_config) { LokaliseRails::GlobalConfig }
|
7
|
+
let(:loc_path) { global_config.locales_path }
|
9
8
|
|
10
9
|
it 'halts when the API key is not set' do
|
11
|
-
allow(
|
10
|
+
allow(global_config).to receive(:api_token).and_return(nil)
|
12
11
|
|
13
12
|
expect(import_executor).to raise_error(SystemExit, /API token is not set/i)
|
14
|
-
expect(
|
13
|
+
expect(global_config).to have_received(:api_token)
|
15
14
|
end
|
16
15
|
|
17
16
|
it 'halts when the project ID is not set' do
|
18
|
-
|
19
|
-
expect(import_executor).to raise_error(SystemExit, /ID is not set/i)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when directory is empty' do
|
24
|
-
before do
|
25
|
-
mkdir_locales
|
26
|
-
rm_translation_files
|
27
|
-
end
|
28
|
-
|
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
|
17
|
+
allow(global_config).to receive(:project_id).and_return(nil)
|
44
18
|
|
45
|
-
|
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
|
-
)
|
19
|
+
expect(import_executor).to raise_error(SystemExit, /ID is not set/i)
|
61
20
|
|
62
|
-
|
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
|
21
|
+
expect(global_config).to have_received(:project_id)
|
70
22
|
end
|
71
23
|
|
72
|
-
context 'when directory is
|
73
|
-
before :all do
|
74
|
-
mkdir_locales
|
75
|
-
described_class.import_safe_mode = true
|
76
|
-
end
|
77
|
-
|
24
|
+
context 'when directory is empty' do
|
78
25
|
before do
|
26
|
+
mkdir_locales
|
79
27
|
rm_translation_files
|
80
|
-
add_translation_files!
|
81
28
|
end
|
82
29
|
|
83
30
|
after :all do
|
84
31
|
rm_translation_files
|
85
|
-
described_class.import_safe_mode = false
|
86
32
|
end
|
87
33
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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)
|
34
|
+
describe 'import' do
|
35
|
+
it 'is callable' do
|
36
|
+
allow_project_id global_config, ENV['LOKALISE_PROJECT_ID'] do
|
37
|
+
VCR.use_cassette('download_files') do
|
38
|
+
expect(import_executor).to output(/complete!/).to_stdout
|
39
|
+
end
|
40
|
+
|
41
|
+
expect(count_translations).to eq(4)
|
42
|
+
|
43
|
+
expect_file_exist loc_path, 'en.yml'
|
44
|
+
expect_file_exist loc_path, 'ru.yml'
|
45
|
+
expect_file_exist loc_path, 'yo.yml'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 're-raises export errors' do
|
50
|
+
allow_project_id global_config, 'fake' do
|
51
|
+
VCR.use_cassette('download_files_error') do
|
52
|
+
expect(import_executor).to raise_error(SystemExit, /Invalid `project_id` parameter/)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
119
56
|
end
|
120
57
|
end
|
121
58
|
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
@@ -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,7 +12,7 @@ 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
|
@@ -41,15 +36,15 @@ module FileManager
|
|
41
36
|
end
|
42
37
|
end
|
43
38
|
|
44
|
-
def add_config!
|
39
|
+
def add_config!(custom_text = '')
|
45
40
|
data = <<~DATA
|
46
|
-
|
47
|
-
LokaliseRails.config do |c|
|
41
|
+
LokaliseRails::GlobalConfig.config do |c|
|
48
42
|
c.api_token = ENV['LOKALISE_API_TOKEN']
|
49
43
|
c.project_id = ENV['LOKALISE_PROJECT_ID']
|
50
|
-
end
|
51
44
|
DATA
|
52
45
|
|
46
|
+
data += custom_text
|
47
|
+
data += "\nend"
|
53
48
|
open_and_write('config/lokalise_rails.rb') { |f| f.write data }
|
54
49
|
end
|
55
50
|
|
data/spec/support/spec_addons.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SpecAddons
|
4
|
-
def
|
5
|
-
|
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(
|
14
|
+
expect(obj).to have_received(:project_id)
|
10
15
|
end
|
11
16
|
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lokalise_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.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-
|
11
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: lokalise_manager
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
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'
|
19
|
+
version: '1.0'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '1.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: codecov
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +58,14 @@ dependencies:
|
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: 6.1.
|
61
|
+
version: 6.1.4
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: 6.1.
|
68
|
+
version: 6.1.4
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rake
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +128,14 @@ dependencies:
|
|
142
128
|
requirements:
|
143
129
|
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: 2.
|
131
|
+
version: 2.5.0
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: 2.
|
138
|
+
version: 2.5.0
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: simplecov
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,11 +184,9 @@ files:
|
|
198
184
|
- lib/generators/lokalise_rails/install_generator.rb
|
199
185
|
- lib/generators/templates/lokalise_rails_config.rb
|
200
186
|
- lib/lokalise_rails.rb
|
201
|
-
- lib/lokalise_rails/
|
187
|
+
- lib/lokalise_rails/global_config.rb
|
202
188
|
- lib/lokalise_rails/railtie.rb
|
203
|
-
- lib/lokalise_rails/
|
204
|
-
- lib/lokalise_rails/task_definition/exporter.rb
|
205
|
-
- lib/lokalise_rails/task_definition/importer.rb
|
189
|
+
- lib/lokalise_rails/utils.rb
|
206
190
|
- lib/lokalise_rails/version.rb
|
207
191
|
- lib/tasks/lokalise_rails_tasks.rake
|
208
192
|
- lokalise_rails.gemspec
|
@@ -229,12 +213,11 @@ files:
|
|
229
213
|
- spec/dummy/config/routes.rb
|
230
214
|
- spec/dummy/db/seeds.rb
|
231
215
|
- spec/lib/generators/lokalise_rails/install_generator_spec.rb
|
232
|
-
- spec/lib/lokalise_rails/
|
233
|
-
- spec/lib/lokalise_rails/task_definition/exporter_spec.rb
|
234
|
-
- spec/lib/lokalise_rails/task_definition/importer_spec.rb
|
216
|
+
- spec/lib/lokalise_rails/global_config_spec.rb
|
235
217
|
- spec/lib/lokalise_rails_spec.rb
|
236
218
|
- spec/lib/tasks/export_task_spec.rb
|
237
219
|
- spec/lib/tasks/import_task_spec.rb
|
220
|
+
- spec/lib/utils_spec.rb
|
238
221
|
- spec/spec_helper.rb
|
239
222
|
- spec/support/file_manager.rb
|
240
223
|
- spec/support/rake_utils.rb
|
@@ -259,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
242
|
- !ruby/object:Gem::Version
|
260
243
|
version: '0'
|
261
244
|
requirements: []
|
262
|
-
rubygems_version: 3.2.
|
245
|
+
rubygems_version: 3.2.26
|
263
246
|
signing_key:
|
264
247
|
specification_version: 4
|
265
248
|
summary: Lokalise integration for Ruby on Rails
|
@@ -287,12 +270,11 @@ test_files:
|
|
287
270
|
- spec/dummy/config/routes.rb
|
288
271
|
- spec/dummy/db/seeds.rb
|
289
272
|
- spec/lib/generators/lokalise_rails/install_generator_spec.rb
|
290
|
-
- spec/lib/lokalise_rails/
|
291
|
-
- spec/lib/lokalise_rails/task_definition/exporter_spec.rb
|
292
|
-
- spec/lib/lokalise_rails/task_definition/importer_spec.rb
|
273
|
+
- spec/lib/lokalise_rails/global_config_spec.rb
|
293
274
|
- spec/lib/lokalise_rails_spec.rb
|
294
275
|
- spec/lib/tasks/export_task_spec.rb
|
295
276
|
- spec/lib/tasks/import_task_spec.rb
|
277
|
+
- spec/lib/utils_spec.rb
|
296
278
|
- spec/spec_helper.rb
|
297
279
|
- spec/support/file_manager.rb
|
298
280
|
- spec/support/rake_utils.rb
|
data/lib/lokalise_rails/error.rb
DELETED
@@ -1,80 +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, {enable_compression: true}.merge(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
|
-
|
62
|
-
# Sends request with exponential backoff mechanism
|
63
|
-
def with_exp_backoff(max_retries)
|
64
|
-
return unless block_given?
|
65
|
-
|
66
|
-
retries = 0
|
67
|
-
begin
|
68
|
-
yield
|
69
|
-
rescue Lokalise::Error::TooManyRequests => e
|
70
|
-
raise(e.class, "Gave up after #{retries} retries") if retries >= max_retries
|
71
|
-
|
72
|
-
sleep 2**retries
|
73
|
-
retries += 1
|
74
|
-
retry
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|