ehbrs-tools 0.16.2 → 0.16.3
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 +4 -4
- data/lib/ehbrs/tools/version.rb +1 -1
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/parser.rb +6 -4
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +10 -2
- data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +6 -3
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +0 -1
- data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
- data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
- data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
- data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
- data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
- metadata +15 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54ab663243b4a28f6150b487f58429b8641562d36227dff9b7088a2233a968b8
|
4
|
+
data.tar.gz: 9951aa6733798e9c4f41468e030edc8145a4bb270caef14c57d24f4d9dd200fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4ac11d9a3d40d9b402c0906dc40825ae88145e02e166ead9de9279911aa4bd410e129bd79b3c3c2dc966ffad17c93870c031cc007e32c1ddeed43e19be92e42
|
7
|
+
data.tar.gz: d2769f8bc2f8471800a8cef1c3763a42fbd4fb32097b4230ac0dc7ede00f7d1c59b29cb9e4b4321639178bdd6695071a2be2b71f49ffbc25ed8742bd87621960
|
data/lib/ehbrs/tools/version.rb
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.files = Dir['{lib}/**/*', 'Gemfile']
|
14
14
|
|
15
|
-
s.add_dependency 'eac_ruby_utils', '~> 0.
|
15
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.55'
|
16
16
|
|
17
17
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
|
18
18
|
end
|
@@ -12,12 +12,14 @@ module EacCli
|
|
12
12
|
|
13
13
|
def parsed_uncached
|
14
14
|
raise 'Definition has no alternatives' if alternatives.empty?
|
15
|
+
raise first_error unless alternatives.select(&:success?).any?
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
17
|
+
alternatives_parsed(true).merge(alternatives_parsed(false))
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
def alternatives_parsed(error)
|
21
|
+
alternatives.select { |a| error == a.error? }.map(&:parsed).reverse
|
22
|
+
.inject(::EacRubyUtils::Struct.new) { |a, e| a.merge(e) }
|
21
23
|
end
|
22
24
|
|
23
25
|
def alternatives_uncached
|
@@ -44,6 +44,8 @@ module EacCli
|
|
44
44
|
extend AfterClassMethods
|
45
45
|
include InstanceMethods
|
46
46
|
::EacCli::Docopt::RunnerExtension.check(self)
|
47
|
+
include ActiveSupport::Callbacks
|
48
|
+
define_callbacks :run
|
47
49
|
end
|
48
50
|
|
49
51
|
module AfterClassMethods
|
@@ -55,8 +57,7 @@ module EacCli
|
|
55
57
|
|
56
58
|
def run(*runner_context_args)
|
57
59
|
r = create(*runner_context_args)
|
58
|
-
r.
|
59
|
-
r.run
|
60
|
+
r.run_run
|
60
61
|
r
|
61
62
|
end
|
62
63
|
|
@@ -72,6 +73,13 @@ module EacCli
|
|
72
73
|
end
|
73
74
|
|
74
75
|
module InstanceMethods
|
76
|
+
def run_run
|
77
|
+
parsed
|
78
|
+
run_callbacks(:run) { run }
|
79
|
+
rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
|
80
|
+
# Do nothing
|
81
|
+
end
|
82
|
+
|
75
83
|
def runner_context
|
76
84
|
return @runner_context if @runner_context
|
77
85
|
|
@@ -13,6 +13,21 @@ module EacCli
|
|
13
13
|
options_argument false
|
14
14
|
bool_opt '-h', '--help', 'Show help.', usage: true
|
15
15
|
end
|
16
|
+
|
17
|
+
set_callback :run, :before do
|
18
|
+
help_run
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def help_run
|
23
|
+
return unless parsed.help?
|
24
|
+
|
25
|
+
puts help_text
|
26
|
+
raise ::EacCli::Runner::Exit
|
27
|
+
end
|
28
|
+
|
29
|
+
def help_text
|
30
|
+
::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
|
16
31
|
end
|
17
32
|
end
|
18
33
|
end
|
@@ -28,7 +28,10 @@ RSpec.describe ::EacCli::Runner do
|
|
28
28
|
|
29
29
|
context 'when all args are supplied' do
|
30
30
|
let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd] }
|
31
|
-
let(:parsed_expected)
|
31
|
+
let(:parsed_expected) do
|
32
|
+
{ opt1: 'aaa', opt2: true, opt3: false, pos1: 'bbb',
|
33
|
+
pos2: %w[ccc ddd] }
|
34
|
+
end
|
32
35
|
|
33
36
|
it { expect(parsed_actual).to eq(parsed_expected) }
|
34
37
|
it { expect(instance.parsed.opt1).to eq('aaa') }
|
@@ -39,7 +42,7 @@ RSpec.describe ::EacCli::Runner do
|
|
39
42
|
|
40
43
|
context 'when only required args are supplied' do
|
41
44
|
let(:argv) { %w[bbb] }
|
42
|
-
let(:parsed_expected) { { opt1: nil, opt2: false, pos1: 'bbb', pos2: [] } }
|
45
|
+
let(:parsed_expected) { { opt1: nil, opt2: false, opt3: false, pos1: 'bbb', pos2: [] } }
|
43
46
|
|
44
47
|
it { expect(parsed_actual).to eq(parsed_expected) }
|
45
48
|
it { expect(instance.parsed.opt1).to be_nil }
|
@@ -58,7 +61,7 @@ RSpec.describe ::EacCli::Runner do
|
|
58
61
|
|
59
62
|
context 'when alternative args are supplied' do
|
60
63
|
let(:argv) { %w[--opt3] }
|
61
|
-
let(:parsed_expected) { { opt3: true } }
|
64
|
+
let(:parsed_expected) { { opt1: nil, opt2: false, opt3: true, pos1: nil, pos2: [] } }
|
62
65
|
|
63
66
|
it { expect(parsed_actual).to eq(parsed_expected) }
|
64
67
|
it { expect(instance.parsed.opt3?).to eq(true) }
|
@@ -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
|
@@ -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,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 @@
|
|
1
|
+
from ubuntu:bionic
|
@@ -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 @@
|
|
1
|
+
from ubuntu:bionic
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
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
|
-
|
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
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'eac_ruby_utils/simple_cache'
|
5
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
class CommonConcern
|
9
|
+
class ClassSetup
|
10
|
+
include ::EacRubyUtils::SimpleCache
|
11
|
+
attr_reader :a_class, :module_setup, :include_method
|
12
|
+
|
13
|
+
def initialize(module_setup, a_class, include_method)
|
14
|
+
@module_setup = module_setup
|
15
|
+
@a_class = a_class
|
16
|
+
@include_method = include_method
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
%w[class_methods instance_methods after_callback].each do |suffix|
|
21
|
+
send("setup_#{suffix}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_class_methods
|
26
|
+
class_methods_module.if_present { |v| a_class.extend v }
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_instance_methods
|
30
|
+
instance_methods_module.if_present { |v| a_class.send(include_method, v) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_after_callback
|
34
|
+
module_setup.common_concern.after_callback.if_present do |v|
|
35
|
+
a_class.instance_eval(&v)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def class_methods_module_uncached
|
40
|
+
module_setup.a_module.const_get(CLASS_METHODS_MODULE_NAME)
|
41
|
+
rescue NameError
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def instance_methods_module_uncached
|
46
|
+
module_setup.a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
|
47
|
+
rescue NameError
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'eac_ruby_utils/common_concern/class_setup'
|
5
|
+
require 'eac_ruby_utils/simple_cache'
|
6
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
7
|
+
|
8
|
+
module EacRubyUtils
|
9
|
+
class CommonConcern
|
10
|
+
class ModuleSetup
|
11
|
+
include ::EacRubyUtils::SimpleCache
|
12
|
+
attr_reader :a_module, :common_concern
|
13
|
+
|
14
|
+
def initialize(common_concern, a_module)
|
15
|
+
@common_concern = common_concern
|
16
|
+
@a_module = a_module
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
setup = self
|
21
|
+
a_module.extend(::ActiveSupport::Concern)
|
22
|
+
a_module.included do
|
23
|
+
::EacRubyUtils::CommonConcern::ClassSetup.new(setup, self, :include).run
|
24
|
+
end
|
25
|
+
a_module.prepended do
|
26
|
+
::EacRubyUtils::CommonConcern::ClassSetup.new(setup, self, :prepend).run
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -61,6 +61,8 @@ module EacRubyUtils
|
|
61
61
|
setup_class_attr_readers(klass)
|
62
62
|
setup_class_attr_writers(klass)
|
63
63
|
setup_class_initialize(klass)
|
64
|
+
|
65
|
+
klass
|
64
66
|
end
|
65
67
|
|
66
68
|
def setup_class_attr_readers(klass)
|
@@ -79,9 +81,14 @@ module EacRubyUtils
|
|
79
81
|
klass.define_callbacks :initialize
|
80
82
|
klass.send(:define_method, :initialize) do |*args|
|
81
83
|
Initialize.new(common_constructor, args, self).run
|
84
|
+
super(*SuperArgs.new(common_constructor, args, self).result)
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
88
|
+
def super_args
|
89
|
+
options[:super_args]
|
90
|
+
end
|
91
|
+
|
85
92
|
class Initialize
|
86
93
|
attr_reader :common_constructor, :args, :object
|
87
94
|
|
@@ -129,5 +136,51 @@ module EacRubyUtils
|
|
129
136
|
" (given #{args.count}, expected #{common_constructor.args_count})"
|
130
137
|
end
|
131
138
|
end
|
139
|
+
|
140
|
+
class SuperArgs
|
141
|
+
attr_reader :common_constructor, :args, :object
|
142
|
+
|
143
|
+
def initialize(common_constructor, args, object)
|
144
|
+
@common_constructor = common_constructor
|
145
|
+
@args = args
|
146
|
+
@object = object
|
147
|
+
end
|
148
|
+
|
149
|
+
def auto_result
|
150
|
+
r = []
|
151
|
+
sub_args.each do |name, value|
|
152
|
+
i = super_arg_index(name)
|
153
|
+
r[i] = value if i
|
154
|
+
end
|
155
|
+
r
|
156
|
+
end
|
157
|
+
|
158
|
+
def result
|
159
|
+
result_from_options || auto_result
|
160
|
+
end
|
161
|
+
|
162
|
+
def result_from_options
|
163
|
+
return unless common_constructor.super_args
|
164
|
+
|
165
|
+
object.instance_exec(&common_constructor.super_args)
|
166
|
+
end
|
167
|
+
|
168
|
+
def sub_args
|
169
|
+
common_constructor.args.each_with_index.map do |name, index|
|
170
|
+
[name, args[index]]
|
171
|
+
end.to_h
|
172
|
+
end
|
173
|
+
|
174
|
+
def super_arg_index(name)
|
175
|
+
super_method.parameters.each_with_index do |arg, index|
|
176
|
+
return index if arg[1] == name
|
177
|
+
end
|
178
|
+
nil
|
179
|
+
end
|
180
|
+
|
181
|
+
def super_method
|
182
|
+
object.class.superclass ? object.class.superclass.instance_method(:initialize) : nil
|
183
|
+
end
|
184
|
+
end
|
132
185
|
end
|
133
186
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'eac_ruby_utils/console/speaker'
|
5
|
-
require 'eac_ruby_utils/envs/command/extra_options'
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
6
4
|
require 'eac_ruby_utils/envs/process'
|
7
5
|
require 'eac_ruby_utils/envs/spawn'
|
8
6
|
require 'pp'
|
@@ -11,8 +9,8 @@ require 'shellwords'
|
|
11
9
|
module EacRubyUtils
|
12
10
|
module Envs
|
13
11
|
class Command
|
14
|
-
|
15
|
-
|
12
|
+
require_sub __FILE__, include_modules: true
|
13
|
+
enable_console_speaker
|
16
14
|
|
17
15
|
def initialize(env, command, extra_options = {})
|
18
16
|
@env = env
|
@@ -47,7 +45,7 @@ module EacRubyUtils
|
|
47
45
|
c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
|
48
46
|
append_command_options(
|
49
47
|
@env.command_line(
|
50
|
-
append_chdir(
|
48
|
+
append_chdir(append_concat(append_envvars(c)))
|
51
49
|
),
|
52
50
|
options
|
53
51
|
)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/struct'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Envs
|
7
|
+
class Command
|
8
|
+
module Concat
|
9
|
+
def concat(operator, other_command)
|
10
|
+
duplicate_by_extra_options(concat: ::EacRubyUtils::Struct.new(
|
11
|
+
operator: operator, command: other_command
|
12
|
+
))
|
13
|
+
end
|
14
|
+
|
15
|
+
def or(other_command)
|
16
|
+
concat('||', other_command)
|
17
|
+
end
|
18
|
+
|
19
|
+
def pipe(other_command)
|
20
|
+
concat('|', other_command)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def append_concat(command)
|
26
|
+
extra_options[:concat].if_present(command) do |v|
|
27
|
+
"#{command} #{v.operator} #{v.command.command}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
module Envs
|
5
|
+
class Command
|
6
|
+
module Envvars
|
7
|
+
def envvar(name, value)
|
8
|
+
duplicate_by_extra_options(envvars: envvars.merge(name => value))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def append_envvars(command)
|
14
|
+
e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
|
15
|
+
e.present? ? "#{e} #{command}" : command
|
16
|
+
end
|
17
|
+
|
18
|
+
def envvars
|
19
|
+
extra_options[:envvars] ||= {}.with_indifferent_access
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -12,39 +12,18 @@ module EacRubyUtils
|
|
12
12
|
duplicate_by_extra_options(chdir: dir)
|
13
13
|
end
|
14
14
|
|
15
|
-
def envvar(name, value)
|
16
|
-
duplicate_by_extra_options(envvars: envvars.merge(name => value))
|
17
|
-
end
|
18
|
-
|
19
15
|
def status_result(status_code, result)
|
20
16
|
duplicate_by_extra_options(status_results: status_results.merge(status_code => result))
|
21
17
|
end
|
22
18
|
|
23
|
-
def pipe(other_command)
|
24
|
-
duplicate_by_extra_options(pipe: other_command)
|
25
|
-
end
|
26
|
-
|
27
19
|
private
|
28
20
|
|
29
21
|
attr_reader :extra_options
|
30
22
|
|
31
|
-
def envvars
|
32
|
-
extra_options[:envvars] ||= {}.with_indifferent_access
|
33
|
-
end
|
34
|
-
|
35
23
|
def status_results
|
36
24
|
extra_options[:status_results] ||= {}.with_indifferent_access
|
37
25
|
end
|
38
26
|
|
39
|
-
def append_envvars(command)
|
40
|
-
e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
|
41
|
-
e.present? ? "#{e} #{command}" : command
|
42
|
-
end
|
43
|
-
|
44
|
-
def append_pipe(command)
|
45
|
-
extra_options[:pipe].present? ? "#{command} | #{extra_options[:pipe].command}" : command
|
46
|
-
end
|
47
|
-
|
48
27
|
def append_chdir(command)
|
49
28
|
extra_options[:chdir].present? ? "(cd '#{extra_options[:chdir]}' ; #{command} )" : command
|
50
29
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/hash_with_indifferent_access'
|
4
|
+
require 'active_support/core_ext/module/delegation'
|
4
5
|
require 'active_support/core_ext/object/blank'
|
5
6
|
|
6
7
|
module EacRubyUtils
|
7
8
|
class Struct
|
8
9
|
def initialize(initial_data = {})
|
9
|
-
self.data =
|
10
|
+
self.data = initial_data.symbolize_keys
|
10
11
|
end
|
11
12
|
|
12
13
|
def [](key)
|
@@ -19,6 +20,11 @@ module EacRubyUtils
|
|
19
20
|
bool ? fetch(key).present? : data.fetch(key)
|
20
21
|
end
|
21
22
|
|
23
|
+
def merge(other)
|
24
|
+
other = self.class.new(other) unless other.is_a?(self.class)
|
25
|
+
self.class.new(to_h.merge(other.to_h))
|
26
|
+
end
|
27
|
+
|
22
28
|
def method_missing(method_name, *arguments, &block)
|
23
29
|
property_method?(method_name) ? fetch(method_name) : super
|
24
30
|
end
|
@@ -9,34 +9,47 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
let(:stub_module) do
|
13
|
+
::Module.new do
|
14
|
+
module ClassMethods # rubocop:disable RSpec/LeakyConstantDeclaration
|
15
|
+
def my_class_method
|
16
|
+
'class'
|
17
|
+
end
|
16
18
|
end
|
17
|
-
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
module InstanceMethods # rubocop:disable RSpec/LeakyConstantDeclaration
|
21
|
+
def my_instance_method
|
22
|
+
'instance'
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
let(:stub_class) do
|
29
|
+
::Class.new do
|
30
|
+
class << self
|
31
|
+
attr_accessor :valor
|
32
|
+
end
|
33
|
+
|
34
|
+
def method1
|
35
|
+
'from_stub_module'
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
|
32
|
-
let(:
|
40
|
+
let(:stub_class_instance) { stub_class.new }
|
33
41
|
|
34
42
|
before do
|
35
|
-
instance.setup(
|
36
|
-
MyClass.include MyModule
|
43
|
+
instance.setup(stub_module)
|
37
44
|
end
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
46
|
+
context 'when included' do
|
47
|
+
before do
|
48
|
+
stub_class.include stub_module
|
49
|
+
end
|
50
|
+
|
51
|
+
it { expect(stub_class_instance.my_instance_method).to eq('instance') }
|
52
|
+
it { expect(stub_class_instance.class.my_class_method).to eq('class') }
|
53
|
+
it { expect(stub_class_instance.class.valor).to eq('changed') }
|
54
|
+
end
|
42
55
|
end
|
@@ -3,34 +3,92 @@
|
|
3
3
|
require 'eac_ruby_utils/common_constructor'
|
4
4
|
|
5
5
|
RSpec.describe ::EacRubyUtils::CommonConstructor do
|
6
|
-
ARG_LIST = %i[a b c d].freeze
|
6
|
+
ARG_LIST = %i[a b c d].freeze # rubocop:disable RSpec/LeakyConstantDeclaration
|
7
|
+
|
7
8
|
let(:instance) do
|
8
9
|
described_class.new(*ARG_LIST, default: %w[Vcc Vd]) do
|
9
10
|
@z = 'Vz'
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
let(:a_class) do
|
15
|
+
::Class.new do
|
16
|
+
attr_reader :z
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
|
-
let(:
|
20
|
+
let(:a_class_instance) { a_class.new('Va', 'Vb', 'Vc') }
|
18
21
|
|
19
22
|
before do
|
20
|
-
instance.setup_class(
|
23
|
+
instance.setup_class(a_class)
|
21
24
|
end
|
22
25
|
|
23
|
-
it { expect(
|
26
|
+
it { expect(a_class_instance.z).to eq('Vz') }
|
24
27
|
|
25
28
|
ARG_LIST.each do |attr|
|
26
29
|
expected_value = "V#{attr}"
|
27
30
|
it "attribute \"#{attr}\" equal to \"#{expected_value}\"" do
|
28
|
-
expect(
|
31
|
+
expect(a_class_instance.send(attr)).to eq(expected_value)
|
29
32
|
end
|
30
33
|
|
31
34
|
[false, true].each do |include_all|
|
32
35
|
it "respond_to?('#{attr}', #{include_all}) == #{include_all}" do
|
33
|
-
expect(
|
36
|
+
expect(a_class_instance.respond_to?("#{attr}=", include_all)).to eq(include_all)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with super class' do
|
42
|
+
let(:super_class) do
|
43
|
+
::Class.new do
|
44
|
+
attr_reader :super_a, :super_b
|
45
|
+
|
46
|
+
def initialize(a, b) # rubocop:disable Naming/MethodParameterName
|
47
|
+
@super_a = a
|
48
|
+
@super_b = b
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:sub_class) do
|
54
|
+
sub_constructor.setup_class(::Class.new(super_class))
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:sub_object) { sub_class.new(1, 2, 3, 4) }
|
58
|
+
|
59
|
+
context 'with super_args parameter' do
|
60
|
+
let(:sub_constructor) do
|
61
|
+
described_class.new(:c, :a, :b, :d, super_args: -> { [c, a] })
|
62
|
+
end
|
63
|
+
|
64
|
+
it { expect(sub_object.a).to eq(2) }
|
65
|
+
it { expect(sub_object.b).to eq(3) }
|
66
|
+
it { expect(sub_object.c).to eq(1) }
|
67
|
+
it { expect(sub_object.d).to eq(4) }
|
68
|
+
it { expect(sub_object.super_a).to eq(1) }
|
69
|
+
it { expect(sub_object.super_b).to eq(2) }
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'without super_args parameter' do
|
73
|
+
let(:sub_constructor) do
|
74
|
+
described_class.new(:c, :a, :b, :d)
|
75
|
+
end
|
76
|
+
|
77
|
+
it { expect(sub_object.a).to eq(2) }
|
78
|
+
it { expect(sub_object.b).to eq(3) }
|
79
|
+
it { expect(sub_object.c).to eq(1) }
|
80
|
+
it { expect(sub_object.d).to eq(4) }
|
81
|
+
it { expect(sub_object.super_a).to eq(2) }
|
82
|
+
it { expect(sub_object.super_b).to eq(3) }
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with undefined super arguments' do
|
86
|
+
let(:sub_constructor) do
|
87
|
+
described_class.new(:x, :y, :w, :a)
|
88
|
+
end
|
89
|
+
|
90
|
+
it do
|
91
|
+
expect { sub_object }.to raise_error(::ArgumentError)
|
34
92
|
end
|
35
93
|
end
|
36
94
|
end
|
@@ -3,7 +3,8 @@
|
|
3
3
|
require 'eac_ruby_utils/struct'
|
4
4
|
|
5
5
|
RSpec.describe ::EacRubyUtils::Struct do
|
6
|
-
let(:instance) { described_class.new(a
|
6
|
+
let(:instance) { described_class.new('a' => 1, b: '') }
|
7
|
+
let(:other) { described_class.new('a' => 'm1', c: 'm2') }
|
7
8
|
|
8
9
|
describe '#[]' do
|
9
10
|
it { expect(instance[:a]).to eq(1) }
|
@@ -35,6 +36,12 @@ RSpec.describe ::EacRubyUtils::Struct do
|
|
35
36
|
it { expect { instance.fetch('c?') }.to raise_error(::KeyError) }
|
36
37
|
end
|
37
38
|
|
39
|
+
describe '#merge' do
|
40
|
+
let(:merged) { instance.merge(other) }
|
41
|
+
|
42
|
+
it { expect(merged.to_h).to eq(a: 'm1', b: '', c: 'm2') }
|
43
|
+
end
|
44
|
+
|
38
45
|
describe '#property_method' do
|
39
46
|
it { expect(instance.a).to eq(1) }
|
40
47
|
it { expect(instance.a?).to eq(true) }
|
@@ -43,4 +50,8 @@ RSpec.describe ::EacRubyUtils::Struct do
|
|
43
50
|
it { expect { instance.c }.to raise_error(::NoMethodError) }
|
44
51
|
it { expect { instance.c? }.to raise_error(::NoMethodError) }
|
45
52
|
end
|
53
|
+
|
54
|
+
describe '#to_h' do
|
55
|
+
it { expect(instance.to_h).to eq(a: 1, b: '') }
|
56
|
+
end
|
46
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avm-tools
|
@@ -253,6 +253,7 @@ files:
|
|
253
253
|
- vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb
|
254
254
|
- vendor/eac_cli/lib/eac_cli/runner.rb
|
255
255
|
- vendor/eac_cli/lib/eac_cli/runner/context.rb
|
256
|
+
- vendor/eac_cli/lib/eac_cli/runner/exit.rb
|
256
257
|
- vendor/eac_cli/lib/eac_cli/runner_with.rb
|
257
258
|
- vendor/eac_cli/lib/eac_cli/runner_with/help.rb
|
258
259
|
- vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb
|
@@ -262,6 +263,7 @@ files:
|
|
262
263
|
- vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb
|
263
264
|
- vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb
|
264
265
|
- vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb
|
266
|
+
- vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb
|
265
267
|
- vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb
|
266
268
|
- vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb
|
267
269
|
- vendor/eac_cli/spec/rubocop_spec.rb
|
@@ -273,10 +275,17 @@ files:
|
|
273
275
|
- vendor/eac_docker/lib/eac_docker/executables.rb
|
274
276
|
- vendor/eac_docker/lib/eac_docker/images.rb
|
275
277
|
- vendor/eac_docker/lib/eac_docker/images/base.rb
|
278
|
+
- vendor/eac_docker/lib/eac_docker/images/coded.rb
|
276
279
|
- vendor/eac_docker/lib/eac_docker/images/named.rb
|
280
|
+
- vendor/eac_docker/lib/eac_docker/images/templatized.rb
|
281
|
+
- vendor/eac_docker/lib/eac_docker/registry.rb
|
277
282
|
- vendor/eac_docker/lib/eac_docker/rspec.rb
|
278
283
|
- vendor/eac_docker/lib/eac_docker/version.rb
|
279
284
|
- vendor/eac_docker/spec/lib/eac_docker/executables_spec.rb
|
285
|
+
- vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb
|
286
|
+
- vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile
|
287
|
+
- vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb
|
288
|
+
- vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile
|
280
289
|
- vendor/eac_docker/spec/rubocop_spec.rb
|
281
290
|
- vendor/eac_docker/spec/spec_helper.rb
|
282
291
|
- vendor/eac_ruby_utils/Gemfile
|
@@ -290,6 +299,8 @@ files:
|
|
290
299
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
|
291
300
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/by_reference.rb
|
292
301
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb
|
302
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb
|
303
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb
|
293
304
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb
|
294
305
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb
|
295
306
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb
|
@@ -316,6 +327,8 @@ files:
|
|
316
327
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/envs.rb
|
317
328
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/base_env.rb
|
318
329
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb
|
330
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb
|
331
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb
|
319
332
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb
|
320
333
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
|
321
334
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/file.rb
|