ehbrs-tools 0.16.0 → 0.16.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/runner/videos/probe.rb +3 -3
  3. data/lib/ehbrs/tools/version.rb +1 -1
  4. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
  5. data/lib/ehbrs/videos/file.rb +4 -8
  6. data/lib/ehbrs/videos/track.rb +5 -13
  7. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +3 -1
  8. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +3 -1
  9. data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +4 -2
  10. data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +3 -1
  11. data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
  12. data/lib/ehbrs/videos/unsupported/fix_profile.rb +0 -13
  13. data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +10 -10
  14. data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
  15. data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
  16. data/vendor/aranha-parsers/Gemfile +5 -0
  17. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  18. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  19. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  20. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  21. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  22. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  23. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  24. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  25. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  26. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  27. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  28. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  29. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  30. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  31. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  32. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  33. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  34. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  35. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  36. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
  37. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  38. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  39. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  40. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  41. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  42. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  43. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  44. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  45. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  46. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  47. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  48. data/vendor/eac_cli/lib/eac_cli/definition.rb +36 -31
  49. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  50. data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
  51. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +15 -2
  52. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  53. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  54. data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
  55. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
  56. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  57. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  58. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  59. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  60. data/vendor/eac_cli/lib/eac_cli/runner.rb +12 -4
  61. data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
  62. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +18 -1
  63. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
  64. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +6 -1
  65. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  66. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
  67. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +10 -0
  68. data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
  69. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +17 -5
  70. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
  71. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  72. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +29 -1
  73. data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
  74. data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
  75. data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
  76. data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
  77. data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
  78. data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
  79. data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
  80. data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
  81. data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
  82. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  83. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
  84. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
  85. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
  86. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
  87. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  89. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  90. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
  91. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  92. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
  93. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
  94. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
  95. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
  96. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  97. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb +2 -2
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
  100. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  102. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  103. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
  104. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
  105. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
  106. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  107. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
  108. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
  109. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
  110. metadata +92 -13
  111. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -127
  112. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
  113. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
  114. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  115. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -23,9 +23,17 @@ RSpec.describe ::EacCli::Runner do
23
23
  end
24
24
  end
25
25
 
26
+ let(:instance) { runner_class.create(argv) }
27
+ let(:parsed_actual) { instance.parsed.to_h.symbolize_keys }
28
+
26
29
  context 'when all args are supplied' do
27
- let(:instance) { runner_class.create(%w[--opt1 aaa --opt2 bbb ccc ddd]) }
30
+ let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd] }
31
+ let(:parsed_expected) do
32
+ { opt1: 'aaa', opt2: true, opt3: false, pos1: 'bbb',
33
+ pos2: %w[ccc ddd] }
34
+ end
28
35
 
36
+ it { expect(parsed_actual).to eq(parsed_expected) }
29
37
  it { expect(instance.parsed.opt1).to eq('aaa') }
30
38
  it { expect(instance.parsed.opt2?).to eq(true) }
31
39
  it { expect(instance.parsed.pos1).to eq('bbb') }
@@ -33,8 +41,10 @@ RSpec.describe ::EacCli::Runner do
33
41
  end
34
42
 
35
43
  context 'when only required args are supplied' do
36
- let(:instance) { runner_class.create(%w[bbb]) }
44
+ let(:argv) { %w[bbb] }
45
+ let(:parsed_expected) { { opt1: nil, opt2: false, opt3: false, pos1: 'bbb', pos2: [] } }
37
46
 
47
+ it { expect(parsed_actual).to eq(parsed_expected) }
38
48
  it { expect(instance.parsed.opt1).to be_nil }
39
49
  it { expect(instance.parsed.opt2?).to eq(false) }
40
50
  it { expect(instance.parsed.pos1).to eq('bbb') }
@@ -42,7 +52,7 @@ RSpec.describe ::EacCli::Runner do
42
52
  end
43
53
 
44
54
  context 'when required args are not supplied' do
45
- let(:instance) { runner_class.create(%w[]) }
55
+ let(:argv) { %w[] }
46
56
 
47
57
  it do
48
58
  expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
@@ -50,8 +60,10 @@ RSpec.describe ::EacCli::Runner do
50
60
  end
51
61
 
52
62
  context 'when alternative args are supplied' do
53
- let(:instance) { runner_class.create(%w[--opt3]) }
63
+ let(:argv) { %w[--opt3] }
64
+ let(:parsed_expected) { { opt1: nil, opt2: false, opt3: true, pos1: nil, pos2: [] } }
54
65
 
66
+ it { expect(parsed_actual).to eq(parsed_expected) }
55
67
  it { expect(instance.parsed.opt3?).to eq(true) }
56
68
  end
57
69
 
@@ -69,7 +81,7 @@ RSpec.describe ::EacCli::Runner do
69
81
  end
70
82
  end
71
83
 
72
- let(:instance) { runner_class.create(%w[aaa bbb]) }
84
+ let(:argv) { %w[aaa bbb] }
73
85
 
74
86
  it do
75
87
  expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/help'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::Help do
7
+ let(:runner) do
8
+ the_module = described_class
9
+ Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ desc 'A stub runner.'
14
+ pos_arg :a_argument
15
+ end
16
+
17
+ def run
18
+ puts 'Runner run'
19
+ end
20
+ end
21
+ end
22
+
23
+ let(:runner_argv) { ['--help'] }
24
+ let(:instance) { runner.create(argv: runner_argv) }
25
+ let(:expected_output) do
26
+ <<~OUTPUT
27
+ A stub runner.
28
+
29
+ Usage:
30
+ __PROGRAM__ [options] <a_argument>
31
+ __PROGRAM__ --help
32
+
33
+ Options:
34
+ -h --help Show help.
35
+
36
+ OUTPUT
37
+ end
38
+
39
+ it 'show help text' do
40
+ expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/output_file'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::OutputFile do
7
+ let(:runner) do
8
+ the_module = described_class
9
+ Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ desc 'A stub root runner.'
14
+ pos_arg :input_text
15
+ end
16
+
17
+ def run
18
+ run_output
19
+ end
20
+
21
+ def output_content
22
+ parsed.input_text
23
+ end
24
+ end
25
+ end
26
+
27
+ let(:stub_text) { 'STUB_TEXT' }
28
+ let(:instance) { runner.create(argv: runner_argv) }
29
+
30
+ context 'without --output-file option' do
31
+ let(:runner_argv) { [stub_text] }
32
+
33
+ it do
34
+ expect { instance.run }.to output(stub_text).to_stdout_from_any_process
35
+ end
36
+ end
37
+
38
+ context 'with --output-file option' do
39
+ let(:output_file) { ::EacRubyUtils::Fs::Temp.file }
40
+ let(:runner_argv) { ['--output-file', output_file.to_path, stub_text] }
41
+
42
+ before do
43
+ instance.run
44
+ end
45
+
46
+ after do
47
+ output_file.remove
48
+ end
49
+
50
+ it { expect(output_file).to exist }
51
+ it { expect(output_file.read).to eq(stub_text) }
52
+ end
53
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_cli/runner'
4
+ require 'eac_cli/runner_with/help'
4
5
  require 'eac_cli/runner_with/subcommands'
5
6
 
6
7
  RSpec.describe ::EacCli::RunnerWith::Subcommands do
@@ -8,7 +9,6 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
8
9
  the_module = described_class
9
10
  the_child = child_runner
10
11
  Class.new do
11
- include ::EacCli::Runner
12
12
  include the_module
13
13
  const_set('ChildCmd', the_child)
14
14
 
@@ -54,4 +54,32 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
54
54
  expect { instance.run }.to raise_error(::EacCli::Parser::Error)
55
55
  end
56
56
  end
57
+
58
+ context 'with help' do
59
+ let(:instance) { parent_runner.create(%w[--help]) }
60
+ let(:expected_output) do
61
+ <<~OUTPUT
62
+ A stub root runner.
63
+
64
+ Usage:
65
+ __PROGRAM__ [options] __SUBCOMMANDS__ [<subcommand_args>...]
66
+ __PROGRAM__ --help
67
+
68
+ Options:
69
+ -r --root-var=<value> A root variable.
70
+ -h --help Show help.
71
+
72
+ Subcommands:
73
+ child-cmd
74
+ OUTPUT
75
+ end
76
+
77
+ before do
78
+ parent_runner.include(::EacCli::RunnerWith::Help)
79
+ end
80
+
81
+ it 'show help text' do
82
+ expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
83
+ end
84
+ end
57
85
  end
@@ -8,6 +8,7 @@ module EacDocker
8
8
  immutable_accessor :interactive, :temporary, :tty, type: :boolean
9
9
  immutable_accessor :env, type: :hash
10
10
  immutable_accessor :command_arg, :volume, type: :array
11
+ attr_reader :id
11
12
  common_constructor :image
12
13
 
13
14
  def immutable_constructor_args
@@ -16,6 +17,23 @@ module EacDocker
16
17
 
17
18
  alias immutable_volume volume
18
19
 
20
+ def hostname
21
+ ::EacDocker::Executables.docker.command(
22
+ 'inspect', '--format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}',
23
+ id
24
+ ).execute!.strip
25
+ end
26
+
27
+ def on_detached
28
+ command = ::EacDocker::Executables.docker.command(*(%w[run --detach] + run_command_args))
29
+ self.id = command.execute!.strip
30
+ begin
31
+ yield(self)
32
+ ensure
33
+ stop
34
+ end
35
+ end
36
+
19
37
  def volume(left_part, right_part = null)
20
38
  immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" })
21
39
  end
@@ -29,8 +47,14 @@ module EacDocker
29
47
  command_args
30
48
  end
31
49
 
50
+ def stop
51
+ ::EacDocker::Executables.docker.command('stop', id).execute!
52
+ end
53
+
32
54
  private
33
55
 
56
+ attr_writer :id
57
+
34
58
  def run_command_boolean_args
35
59
  r = []
36
60
  r << '--interactive' if interactive?
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/executables'
4
+ require 'eac_docker/images/base'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EacDocker
8
+ module Images
9
+ class Coded < ::EacDocker::Images::Base
10
+ enable_simple_cache
11
+ enable_immutable
12
+ immutable_accessor :tag
13
+ common_constructor :path do
14
+ self.path = path.to_pathname
15
+ end
16
+
17
+ def immutable_constructor_args
18
+ [path]
19
+ end
20
+
21
+ def provide
22
+ id
23
+ self
24
+ end
25
+
26
+ private
27
+
28
+ def id_uncached
29
+ ::EacDocker::Executables.docker.command(*build_args).execute!.strip
30
+ end
31
+
32
+ def build_args
33
+ args = %w[build --quiet]
34
+ args += ['--tag', tag] if tag.present?
35
+ args + [path.to_path]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/images/base'
4
+ require 'eac_docker/images/coded'
5
+ require 'eac_ruby_utils/core_ext'
6
+ require 'eac_ruby_utils/fs/temp'
7
+
8
+ module EacDocker
9
+ module Images
10
+ class Templatized < ::EacDocker::Images::Base
11
+ enable_immutable
12
+ immutable_accessor :tag
13
+
14
+ def provide
15
+ ::EacRubyUtils::Fs::Temp.on_directory do |provide_dir|
16
+ template.apply(self, provide_dir)
17
+ coded_image(provide_dir).tag(tag).provide
18
+ end
19
+ end
20
+
21
+ def coded_image(provide_dir)
22
+ ::EacDocker::Images::Coded.new(provide_dir)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacDocker
6
+ class Registry
7
+ common_constructor :name
8
+
9
+ def to_s
10
+ name
11
+ end
12
+
13
+ def sub(suffix)
14
+ self.class.new("#{name}#{suffix}")
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacDocker
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/images/coded'
4
+
5
+ RSpec.describe(::EacDocker::Images::Coded, docker: true) do
6
+ let(:fixtures_dir) { ::Pathname.new('coded_spec_files').expand_path(__dir__) }
7
+ let(:instance) { described_class.new(fixtures_dir / 'image1') }
8
+
9
+ describe '#provide' do
10
+ it { expect { instance.provide }.not_to raise_error }
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/images/templatized'
4
+
5
+ RSpec.describe(::EacDocker::Images::Templatized, docker: true) do
6
+ let(:fixtures_dir) { ::Pathname.new('templatized_spec_files').expand_path(__dir__) }
7
+ let(:instance) { StubDockerImage.new }
8
+
9
+ before do
10
+ ::EacRubyUtils::Templates::Searcher.default.included_paths << fixtures_dir
11
+ stub_const('StubDockerImage', Class.new(described_class))
12
+ end
13
+
14
+ describe '#provide' do
15
+ it { expect { instance.provide }.not_to raise_error }
16
+ end
17
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/common_concern'
4
+
5
+ module EacRubyUtils
6
+ # Support to abstract methods.
7
+ #
8
+ # Usage:
9
+ #
10
+ # require 'eac_ruby_utils/abstract_methods'
11
+ #
12
+ # class BaseClass
13
+ # include EacRubyUtils::AbstractMethods
14
+ #
15
+ # abstract_methods :mymethod
16
+ # end
17
+ #
18
+ # BaseClass.new.mymethod # raise "Abstract method: mymethod"
19
+ #
20
+ # class SubClass
21
+ # def mymethod
22
+ # "Implemented"
23
+ # end
24
+ # end
25
+ #
26
+ # SubClass.new.mymethod # return "Implemented"
27
+ module AbstractMethods
28
+ common_concern
29
+
30
+ module ClassMethods
31
+ def abstract_methods(*methods_names)
32
+ methods_names.each do |method_name|
33
+ define_method method_name do
34
+ raise_abstract_method(method_name)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ module InstanceMethods
41
+ def respond_to_missing?(method_name, include_private = false)
42
+ super || abstract_method?(method_name)
43
+ end
44
+
45
+ def method_missing(method_name, *arguments, &block)
46
+ raise_abstract_method(method_name) if abstract_method?(method_name)
47
+
48
+ super
49
+ end
50
+
51
+ def abstract_method?(method_name)
52
+ self.class.abstract_methods.include?(method_name.to_sym)
53
+ end
54
+
55
+ def raise_abstract_method(method_name)
56
+ raise ::NoMethodError, "Abstract method \"#{method_name}\" hit in \"#{self}\""
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/concern'
4
- require 'eac_ruby_utils/simple_cache'
5
- require 'eac_ruby_utils/patches/object/if_present'
3
+ require 'eac_ruby_utils/common_concern/module_setup'
6
4
 
7
5
  module EacRubyUtils
8
6
  class CommonConcern
@@ -16,53 +14,7 @@ module EacRubyUtils
16
14
  end
17
15
 
18
16
  def setup(a_module)
19
- Setup.new(self, a_module).run
20
- end
21
-
22
- class Setup
23
- include ::EacRubyUtils::SimpleCache
24
- attr_reader :a_module, :common_concern
25
-
26
- def initialize(common_concern, a_module)
27
- @common_concern = common_concern
28
- @a_module = a_module
29
- end
30
-
31
- def run
32
- setup = self
33
- a_module.extend(::ActiveSupport::Concern)
34
- a_module.included do
35
- %w[class_methods instance_methods after_callback].each do |suffix|
36
- setup.send("setup_#{suffix}", self)
37
- end
38
- end
39
- end
40
-
41
- def setup_class_methods(base)
42
- class_methods_module.if_present { |v| base.extend v }
43
- end
44
-
45
- def setup_instance_methods(base)
46
- instance_methods_module.if_present { |v| base.include v }
47
- end
48
-
49
- def setup_after_callback(base)
50
- common_concern.after_callback.if_present do |v|
51
- base.instance_eval(&v)
52
- end
53
- end
54
-
55
- def class_methods_module_uncached
56
- a_module.const_get(CLASS_METHODS_MODULE_NAME)
57
- rescue NameError
58
- nil
59
- end
60
-
61
- def instance_methods_module_uncached
62
- a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
63
- rescue NameError
64
- nil
65
- end
17
+ ::EacRubyUtils::CommonConcern::ModuleSetup.new(self, a_module).run
66
18
  end
67
19
  end
68
20
  end