ehbrs-tools 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +13 -0
- data/exe/ehbrs +6 -0
- data/lib/ehbrs.rb +7 -0
- data/lib/ehbrs/executables.rb +28 -0
- data/lib/ehbrs/tools.rb +9 -0
- data/lib/ehbrs/tools/runner.rb +35 -0
- data/lib/ehbrs/tools/runner/vg.rb +26 -0
- data/lib/ehbrs/tools/runner/vg/ips.rb +90 -0
- data/lib/ehbrs/tools/runner/videos.rb +25 -0
- data/lib/ehbrs/tools/runner/videos/unsupported.rb +65 -0
- data/lib/ehbrs/tools/version.rb +7 -0
- data/lib/ehbrs/videos.rb +9 -0
- data/lib/ehbrs/videos/convert_job.rb +99 -0
- data/lib/ehbrs/videos/file.rb +70 -0
- data/lib/ehbrs/videos/profiles/base.rb +35 -0
- data/lib/ehbrs/videos/profiles/same_quality.rb +21 -0
- data/lib/ehbrs/videos/track.rb +27 -0
- data/lib/ehbrs/videos/unsupported/check_result.rb +24 -0
- data/lib/ehbrs/videos/unsupported/check_set.rb +43 -0
- data/lib/ehbrs/videos/unsupported/check_support.rb +68 -0
- data/lib/ehbrs/videos/unsupported/checks.rb +13 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +27 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +26 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +23 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +25 -0
- data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +25 -0
- data/lib/ehbrs/videos/unsupported/file.rb +50 -0
- data/lib/ehbrs/videos/unsupported/file/fix.rb +45 -0
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +56 -0
- data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +36 -0
- data/lib/ehbrs/videos/unsupported/fixes/supported_container.rb +17 -0
- data/lib/ehbrs/videos/unsupported/profiles.rb +13 -0
- data/lib/ehbrs/videos/unsupported/profiles/base.rb +102 -0
- data/lib/ehbrs/videos/unsupported/profiles/philco.rb +27 -0
- data/lib/ehbrs/videos/unsupported/profiles/samsung.rb +32 -0
- data/lib/ehbrs/videos/unsupported/search.rb +72 -0
- data/lib/ehbrs/videos/unsupported/track.rb +32 -0
- data/vendor/eac_cli/Gemfile +5 -0
- data/vendor/eac_cli/eac_cli.gemspec +18 -0
- data/vendor/eac_cli/lib/eac_cli.rb +7 -0
- data/vendor/eac_cli/lib/eac_cli/default_runner.rb +22 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner/base_option.rb +22 -0
- data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +60 -0
- data/vendor/eac_cli/lib/eac_cli/runner/docopt_doc.rb +65 -0
- data/vendor/eac_cli/lib/eac_cli/runner/positional_argument.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +5 -0
- data/vendor/eac_cli/spec/rubocop_spec.rb +7 -0
- data/vendor/eac_cli/spec/spec_helper.rb +100 -0
- data/vendor/eac_ruby_utils/Gemfile +16 -0
- data/vendor/eac_ruby_utils/MIT-LICENCE +16 -0
- data/vendor/eac_ruby_utils/README.rdoc +3 -0
- data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/arguments_consumer.rb +81 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +133 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +82 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +66 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +135 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +39 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_doc.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_settings.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +139 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +134 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker/_class_methods.rb +39 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker/list.rb +63 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker/node.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/contextualizable.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/core_ext.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/base_env.rb +28 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +155 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +46 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +51 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/file.rb +22 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/local_env.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/process.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +72 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_traverser.rb +56 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/class_methods.rb +14 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/instance_methods.rb +30 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/integer_list.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +89 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +61 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/string_list.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +38 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/on_clean_ruby_environment.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/options_consumer.rb +62 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patch.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/common_constructor.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/console_speaker.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/listable.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/simple_cache.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb +14 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +12 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +95 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec/conditional.rb +38 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec/stubbed_ssh.rb +44 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider.rb +65 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +42 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/directory.rb +104 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/file.rb +101 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/searcher.rb +55 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/arguments_consumer_spec.rb +17 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +36 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +31 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/configs_spec.rb +14 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +136 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +36 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +33 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/ssh_env_spec.rb +25 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/filesystem_cache_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +180 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +45 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/options_consumer_spec.rb +17 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/console_speaker_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/listable_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/simple_cache_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +23 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec_files/path/my_stub_with_template +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +49 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/settings_provider_spec.rb +46 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/simple_cache_spec.rb +102 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec.rb +34 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec_files/expected_content +2 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec_files/source.template +2 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +30 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec_files/path1/subdir1/file1.template +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec_files/path1/subdir1/file2 +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec_files/path2/subdir1/file3.template +1 -0
- data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +38 -0
- data/vendor/eac_ruby_utils/spec/spec_helper.rb +12 -0
- metadata +227 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/options_consumer'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::OptionsConsumer do
|
6
|
+
context 'instance created with some data' do
|
7
|
+
subject(:instance) { described_class.new(a: 'a_value', b: 'b_value', c: 'c_value') }
|
8
|
+
|
9
|
+
it 'left data should be Hash' do
|
10
|
+
expect(instance.left_data).to be_a(::Hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'left data should be not empty' do
|
14
|
+
expect { instance.validate }.to raise_error(::StandardError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'parses args' do
|
18
|
+
expect(instance.left_data).to eq({ a: 'a_value', b: 'b_value', c: 'c_value' }
|
19
|
+
.with_indifferent_access)
|
20
|
+
expect(instance.consume(:a)).to eq('a_value')
|
21
|
+
expect(instance.left_data).to eq({ b: 'b_value', c: 'c_value' }.with_indifferent_access)
|
22
|
+
expect(instance.consume(:c)).to eq('c_value')
|
23
|
+
expect(instance.left_data).to eq({ b: 'b_value' }.with_indifferent_access)
|
24
|
+
expect(instance.consume(:b)).to eq('b_value')
|
25
|
+
expect(instance.left_data).to eq({}.with_indifferent_access)
|
26
|
+
instance.validate
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'raises if validate has left data' do
|
30
|
+
expect(instance.left_data.empty?).to eq(false)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '#consume_all' do
|
35
|
+
subject(:instance) { described_class.new(a: 'a_value', b: 'b_value', c: 'c_value') }
|
36
|
+
|
37
|
+
it 'return all options in arguments' do
|
38
|
+
a, b, c, d = instance.consume_all(:a, :b, :c, :d)
|
39
|
+
expect(a).to eq('a_value')
|
40
|
+
expect(b).to eq('b_value')
|
41
|
+
expect(c).to eq('c_value')
|
42
|
+
expect(d).to eq(nil)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/hash/options_consumer'
|
4
|
+
|
5
|
+
RSpec.describe ::Hash do
|
6
|
+
let(:a_hash) { { a: 'a_value', b: 'b_value', c: 'c_value' } }
|
7
|
+
let(:instance) { a_hash.to_options_consumer }
|
8
|
+
|
9
|
+
it 'returns a OptionsConsumer' do
|
10
|
+
expect(instance).to be_a(::EacRubyUtils::OptionsConsumer)
|
11
|
+
end
|
12
|
+
|
13
|
+
it do
|
14
|
+
expect(instance.left_data).to eq({ a: 'a_value', b: 'b_value', c: 'c_value' }
|
15
|
+
.with_indifferent_access)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/hash/sym_keys_hash'
|
4
|
+
|
5
|
+
RSpec.describe ::Hash do
|
6
|
+
let(:a_hash) { { 'a' => 'a_value', 1 => '1_value', s: 's_value' } }
|
7
|
+
|
8
|
+
context '#to_sym_keys_hash' do
|
9
|
+
it 'converts all keys to symbols' do
|
10
|
+
expect(a_hash.to_sym_keys_hash).to eq(a: 'a_value', '1': '1_value', s: 's_value')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/module/console_speaker'
|
4
|
+
|
5
|
+
RSpec.describe ::Module do
|
6
|
+
class StubClass
|
7
|
+
enable_console_speaker
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#enable_console_speaker' do
|
11
|
+
it { expect(StubClass.included_modules).to include(::EacRubyUtils::Console::Speaker) }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/module/listable'
|
4
|
+
|
5
|
+
RSpec.describe ::Module do
|
6
|
+
class StubClass
|
7
|
+
enable_listable
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#enable_listable' do
|
11
|
+
it { expect(StubClass.included_modules).to include(::EacRubyUtils::Listable) }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/module/simple_cache'
|
4
|
+
|
5
|
+
RSpec.describe ::Module do
|
6
|
+
class StubClass
|
7
|
+
enable_simple_cache
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#enable_simple_cache' do
|
11
|
+
it { expect(StubClass.included_modules).to include(::EacRubyUtils::SimpleCache) }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
4
|
+
|
5
|
+
RSpec.describe ::Object do
|
6
|
+
context '#if_present' do
|
7
|
+
it { expect(nil.if_present).to eq(nil) }
|
8
|
+
it { expect(nil.if_present('default')) .to eq('default') }
|
9
|
+
it { expect(nil.if_present('default') { |_v| 'calculated' }).to eq('default') }
|
10
|
+
it { expect('present'.if_present('default')).to eq('present') }
|
11
|
+
it { expect('present'.if_present { |v| v + '_calculated' }) .to eq('present_calculated') }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/object/template'
|
4
|
+
|
5
|
+
RSpec.describe ::Object do
|
6
|
+
class MyStubWithTemplate
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:instance) { ::MyStubWithTemplate.new }
|
10
|
+
let(:templates_path) { ::File.join(__dir__, 'template_spec_files', 'path') }
|
11
|
+
|
12
|
+
before do
|
13
|
+
::EacRubyUtils::Templates::Searcher.default.included_paths.add(templates_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
::EacRubyUtils::Templates::Searcher.default.included_paths.delete(templates_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#template' do
|
21
|
+
it { expect(instance.template).to be_a(::EacRubyUtils::Templates::File) }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/paths_hash'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::PathsHash do
|
6
|
+
describe '#[]' do
|
7
|
+
let(:source_hash) do
|
8
|
+
{
|
9
|
+
parent: {
|
10
|
+
child1: {
|
11
|
+
child1_1: 'v1_1',
|
12
|
+
child1_2: 'v1_2'
|
13
|
+
},
|
14
|
+
child2: 'v2'
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
let(:instance) { described_class.new(source_hash) }
|
19
|
+
|
20
|
+
{
|
21
|
+
'parent.child1.child1_1' => 'v1_1',
|
22
|
+
'parent.child1.child1_2' => 'v1_2',
|
23
|
+
'parent.child2' => 'v2',
|
24
|
+
'no_exist' => nil,
|
25
|
+
'parent.child1' => {
|
26
|
+
child1_1: 'v1_1',
|
27
|
+
child1_2: 'v1_2'
|
28
|
+
}
|
29
|
+
}.each do |entry_key, expected_value|
|
30
|
+
it { expect(instance[entry_key]).to eq(expected_value) }
|
31
|
+
end
|
32
|
+
|
33
|
+
['.only_suffix', '', '.', 'only_prefx.', 'empty..part'].each do |entry_key|
|
34
|
+
it "invalid entry key \"#{entry_key}\" raises EntryKeyError" do
|
35
|
+
expect { instance[entry_key] }.to raise_error(::EacRubyUtils::PathsHash::EntryKeyError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#[]=' do
|
41
|
+
let(:instance) { described_class.new }
|
42
|
+
|
43
|
+
before do
|
44
|
+
instance['a.b.c'] = '123'
|
45
|
+
end
|
46
|
+
|
47
|
+
it { expect(instance.to_h).to eq(a: { b: { c: '123' } }) }
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/settings_provider'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::SettingsProvider do
|
6
|
+
class MyStubSettingsProvided
|
7
|
+
include ::EacRubyUtils::SettingsProvider
|
8
|
+
|
9
|
+
KEY_A = 'constant_a'
|
10
|
+
KEY_D = 'constant_d'
|
11
|
+
|
12
|
+
def key_a
|
13
|
+
'method_a'
|
14
|
+
end
|
15
|
+
|
16
|
+
def key_b
|
17
|
+
'method_b'
|
18
|
+
end
|
19
|
+
|
20
|
+
def settings
|
21
|
+
{ 'key_b' => 'setting_b', key_c: 'setting_c' }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:stub) { MyStubSettingsProvided.new }
|
26
|
+
|
27
|
+
describe '#setting_value' do
|
28
|
+
{
|
29
|
+
['key_a'] => 'method_a',
|
30
|
+
[:key_b] => 'setting_b',
|
31
|
+
['key_b', { order: %w[constant method settings_object] }] => 'method_b',
|
32
|
+
['key_c'] => 'setting_c',
|
33
|
+
['key_d'] => 'constant_d'
|
34
|
+
}.each do |args, expected_value|
|
35
|
+
it { expect(stub.setting_value(*args)).to eq(expected_value) }
|
36
|
+
end
|
37
|
+
|
38
|
+
it do
|
39
|
+
expect { stub.setting_value('key_e') }.to raise_error(::StandardError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it do
|
43
|
+
expect(stub.setting_value('key_e', required: false)).to eq(nil)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/simple_cache'
|
4
|
+
|
5
|
+
class CacheableObject
|
6
|
+
include ::EacRubyUtils::SimpleCache
|
7
|
+
|
8
|
+
def my_method_uncached
|
9
|
+
@counter ||= 0
|
10
|
+
@counter += 1
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_with_args_uncached(arg1)
|
14
|
+
@counter2 ||= 0
|
15
|
+
@counter2 += 1
|
16
|
+
"#{arg1}/#{@counter2}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def private_method_uncached
|
22
|
+
@counter3 ||= 0
|
23
|
+
@counter3 += 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.describe ::EacRubyUtils::SimpleCache do
|
28
|
+
let(:instance) { CacheableObject.new }
|
29
|
+
|
30
|
+
describe 'cached value' do
|
31
|
+
it 'uncached method return value should update at each call' do
|
32
|
+
expect(instance.my_method_uncached).not_to eq(instance.my_method_uncached)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'cached method should return same values at each call' do
|
36
|
+
expect(instance.my_method).to eq(instance.my_method)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is able to call private uncached as cached' do
|
40
|
+
expect(instance.private_method).to eq(instance.private_method)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'cache value with args' do
|
45
|
+
it do
|
46
|
+
expect(instance.method_with_args_uncached('123'))
|
47
|
+
.not_to eq(instance.method_with_args_uncached('123'))
|
48
|
+
end
|
49
|
+
|
50
|
+
it do
|
51
|
+
expect(instance.method_with_args_uncached('456'))
|
52
|
+
.not_to eq(instance.method_with_args_uncached('456'))
|
53
|
+
end
|
54
|
+
|
55
|
+
it do
|
56
|
+
expect(instance.method_with_args('123')).to eq(instance.method_with_args('123'))
|
57
|
+
end
|
58
|
+
|
59
|
+
it do
|
60
|
+
expect(instance.method_with_args('456')).to eq(instance.method_with_args('456'))
|
61
|
+
end
|
62
|
+
|
63
|
+
it do
|
64
|
+
expect(instance.method_with_args('456')).not_to eq(instance.method_with_args('123'))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#respond_to?' do
|
69
|
+
it 'responds to cached method without args' do
|
70
|
+
expect(instance.respond_to?(:my_method)).to be(true)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'responds to cached method with args' do
|
74
|
+
expect(instance.respond_to?(:method_with_args)).to be(true)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'responds to cached method of uncached private method' do
|
78
|
+
expect(instance.respond_to?(:private_method)).to be(true)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'not respond to not existent method' do
|
82
|
+
expect(instance.respond_to?(:not_exist)).to be(false)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#reset_cache' do
|
87
|
+
let(:instance) { CacheableObject.new }
|
88
|
+
let(:cached_value) { instance.my_method }
|
89
|
+
|
90
|
+
it 'cached method return should return cached value' do
|
91
|
+
expect(instance.my_method).to eq(cached_value)
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when reset_cache method is called' do
|
95
|
+
it 'cached method return should return new cached value' do
|
96
|
+
cached_value
|
97
|
+
instance.reset_cache
|
98
|
+
expect(instance.my_method).not_to eq(cached_value)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/templates/file'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Templates::File do
|
6
|
+
let(:files_dir) { ::File.join(__dir__, 'file_spec_files') }
|
7
|
+
let(:source_path) { ::File.join(files_dir, 'source.template') }
|
8
|
+
let(:instance) { described_class.new(source_path) }
|
9
|
+
let(:expected_content) { ::File.read(::File.join(files_dir, 'expected_content')) }
|
10
|
+
|
11
|
+
describe '#apply' do
|
12
|
+
context 'when config is a hash' do
|
13
|
+
let(:config) { { name: 'Fulano de Tal', age: 33 } }
|
14
|
+
|
15
|
+
it { expect(instance.apply(config)).to eq(expected_content) }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when config responds to read_entry' do
|
19
|
+
let(:config) { ::EacRubyUtils::Configs.new('rspec_describe_eac_ruby_utils_templates_file') }
|
20
|
+
|
21
|
+
before do
|
22
|
+
config.clear
|
23
|
+
config['name'] = 'Fulano de Tal'
|
24
|
+
config['age'] = '33'
|
25
|
+
end
|
26
|
+
|
27
|
+
it { expect(instance.apply(config)).to eq(expected_content) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#variables' do
|
32
|
+
it { expect(instance.variables).to eq(::Set.new(%w[name age])) }
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/templates/searcher'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Templates::Searcher do
|
6
|
+
let(:files_dir) { ::File.join(__dir__, 'searcher_spec_files') }
|
7
|
+
let(:instance) do
|
8
|
+
r = described_class.new
|
9
|
+
r.included_paths << ::File.join(files_dir, 'path1')
|
10
|
+
r.included_paths << ::File.join(files_dir, 'path2')
|
11
|
+
r
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#template' do
|
15
|
+
{
|
16
|
+
::EacRubyUtils::Templates::Directory => %w[subdir1],
|
17
|
+
::EacRubyUtils::Templates::File => %w[subdir1/file1.template subdir1/file2
|
18
|
+
subdir1/file3.template],
|
19
|
+
::NilClass => %w[does_not_exist]
|
20
|
+
}.each do |klass, subpaths|
|
21
|
+
subpaths.each do |subpath|
|
22
|
+
context "when subpath is \"#{subpath}\"" do
|
23
|
+
it "should return a #{klass}'s instance" do
|
24
|
+
expect(instance.template(subpath, false)).to be_a(klass)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|