eac_tools 0.66.0 → 0.67.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +32 -32
- data/lib/eac_tools/version.rb +1 -1
- data/sub/avm/avm.gemspec +2 -2
- data/sub/avm/lib/avm/data/clearer.rb +8 -6
- data/sub/avm/lib/avm/data/package/base_performer.rb +38 -0
- data/sub/avm/lib/avm/data/package/clear.rb +3 -4
- data/sub/avm/lib/avm/data/performer.rb +49 -0
- data/sub/avm/lib/avm/instances/base/subcommand_parent.rb +5 -5
- data/sub/avm/lib/avm/instances/runner.rb +1 -1
- data/sub/avm/lib/avm/scms/auto_commit/for_file.rb +12 -2
- data/sub/avm/lib/avm/sources/runner.rb +2 -0
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm-eac_ubuntu_base0/avm-eac_ubuntu_base0.gemspec +3 -3
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/runners/base.rb +2 -0
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/version.rb +1 -1
- data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +3 -3
- data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/provider.rb +2 -2
- data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
- data/sub/avm-git/avm-git.gemspec +2 -2
- data/sub/avm-git/lib/avm/git/scms/git/commit_dirty.rb +35 -0
- data/sub/avm-git/lib/avm/git/scms/git/commits.rb +0 -14
- data/sub/avm-git/lib/avm/git/scms/git/run_commit.rb +1 -1
- data/sub/avm-git/lib/avm/git/scms/git_sub_base/changed_file.rb +21 -0
- data/sub/avm-git/lib/avm/git/scms/git_sub_base/commit.rb +1 -3
- data/sub/avm-git/lib/avm/git/scms/git_sub_base.rb +8 -1
- data/sub/avm-git/lib/avm/git/version.rb +1 -1
- data/sub/avm-tools/avm-tools.gemspec +2 -2
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/clear.rb +1 -1
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/dump.rb +2 -2
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/load.rb +1 -1
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit.rb +2 -5
- data/sub/avm-tools/lib/avm/tools/runner/instance/data.rb +2 -0
- data/sub/avm-tools/lib/avm/tools/runner_with/include_exclude.rb +23 -0
- data/sub/avm-tools/lib/avm/tools/runner_with/instance_data_clear.rb +11 -1
- data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
- data/sub/eac_cli/eac_cli.gemspec +1 -1
- data/sub/eac_cli/lib/eac_cli/definition/alternative.rb +11 -7
- data/sub/eac_cli/lib/eac_cli/definition/base_option/initialize_args_parser.rb +2 -1
- data/sub/eac_cli/lib/eac_cli/definition/base_option.rb +1 -1
- data/sub/eac_cli/lib/eac_cli/definition/boolean_option.rb +2 -1
- data/sub/eac_cli/lib/eac_cli/definition/error.rb +8 -0
- data/sub/eac_cli/lib/eac_cli/runner/after_class_methods.rb +6 -1
- data/sub/eac_cli/lib/eac_cli/runner/context.rb +22 -3
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/base.rb +24 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/parent.rb +27 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner.rb +20 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner_missing_method.rb +32 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb +44 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders.rb +11 -0
- data/sub/eac_cli/lib/eac_cli/runner/for_context.rb +40 -0
- data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +5 -3
- data/sub/eac_cli/lib/eac_cli/runner.rb +1 -0
- data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
- data/sub/eac_cli/spec/lib/eac_cli/runner/for_context_spec.rb +79 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +1 -0
- data/sub/eac_ruby_base0/eac_ruby_base0.gemspec +3 -3
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb +52 -0
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner/prepend.rb +17 -4
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +1 -39
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_abstract.rb +17 -6
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/array_accessor.rb +25 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb +57 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/boolean_accessor.rb +3 -3
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/class_methods.rb +2 -2
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/common_accessor.rb +5 -5
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable/array_accessor.rb → acts_as_immutable/enumerable_accessor.rb} +11 -8
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor.rb +5 -5
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/instance_methods.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/set_accessor.rb +25 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable.rb → acts_as_immutable.rb} +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/enumerables_methods.rb +42 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/base.rb +34 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/hash.rb +20 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/set.rb +19 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable.rb +9 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/acts_as_immutable.rb +10 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +3 -2
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +9 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/unimplemented_method_error.rb +6 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_abstract_spec.rb +73 -7
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{immutable → acts_as_immutable}/array_accessor_spec.rb +11 -3
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_immutable/common_accessor_spec.rb +57 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor_spec.rb +3 -3
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_immutable/set_accessor_spec.rb +43 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/enumerables_methods_spec.rb +50 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/module_ancestors_variable/hash_spec.rb +57 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/module_ancestors_variable/set_spec.rb +57 -0
- metadata +57 -22
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +0 -23
@@ -15,7 +15,7 @@ module Avm
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def run
|
18
|
-
|
18
|
+
data_owner.dump(dump_path)
|
19
19
|
end
|
20
20
|
|
21
21
|
# @return [String]
|
@@ -30,7 +30,7 @@ module Avm
|
|
30
30
|
|
31
31
|
# @return [String]
|
32
32
|
def default_dump_path
|
33
|
-
|
33
|
+
data_owner.data_default_dump_path
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -15,6 +15,8 @@ module Avm
|
|
15
15
|
subcommands
|
16
16
|
end
|
17
17
|
|
18
|
+
for_context :data_owner
|
19
|
+
|
18
20
|
# @return [Enumerable<String>]
|
19
21
|
def available_units_ids
|
20
22
|
data_package.units_ids
|
@@ -27,11 +29,6 @@ module Avm
|
|
27
29
|
|
28
30
|
# @return [Avm::Instances::Data::Unit]
|
29
31
|
def data_owner
|
30
|
-
data_unit
|
31
|
-
end
|
32
|
-
|
33
|
-
# @return [Avm::Instances::Data::Unit]
|
34
|
-
def data_unit
|
35
32
|
data_package.unit(parsed.identifier)
|
36
33
|
end
|
37
34
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'eac_cli/runner'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Tools
|
8
|
+
module RunnerWith
|
9
|
+
module IncludeExclude
|
10
|
+
common_concern do
|
11
|
+
include ::EacCli::Runner
|
12
|
+
|
13
|
+
runner_definition do
|
14
|
+
arg_opt '-I', '--include', repeat: true
|
15
|
+
arg_opt '-E', '--exclude', repeat: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
delegate :include, :exclude, to: :parsed
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'avm/data/clearer'
|
3
4
|
require 'eac_cli/core_ext'
|
4
5
|
require 'eac_cli/runner'
|
5
6
|
|
@@ -8,11 +9,20 @@ module Avm
|
|
8
9
|
module RunnerWith
|
9
10
|
module InstanceDataClear
|
10
11
|
common_concern do
|
12
|
+
enable_simple_cache
|
11
13
|
include ::EacCli::Runner
|
12
14
|
end
|
13
15
|
|
14
16
|
def run
|
15
|
-
|
17
|
+
performer.perform
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def performer_uncached
|
23
|
+
%i[include exclude].inject(::Avm::Data::Clearer.new(data_owner)) do |a1, e1|
|
24
|
+
if_respond(e1, []).inject(a1) { |a2, e2| a2.send(e1, e2) }
|
25
|
+
end
|
16
26
|
end
|
17
27
|
end
|
18
28
|
end
|
data/sub/eac_cli/eac_cli.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.add_dependency 'colorize', '~> 0.8', '>= 0.8.1'
|
16
16
|
s.add_dependency 'eac_config', '~> 0.12'
|
17
|
-
s.add_dependency 'eac_ruby_utils', '~> 0.
|
17
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.117'
|
18
18
|
|
19
19
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
|
20
20
|
end
|
@@ -42,14 +42,15 @@ module EacCli
|
|
42
42
|
pos_set.to_a
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def positional_arguments_blocked_reason(new_pos_arg)
|
46
46
|
last = pos_set.last
|
47
|
-
return
|
48
|
-
return
|
49
|
-
return
|
50
|
-
return
|
47
|
+
return nil unless last
|
48
|
+
return 'there are subcommands' if subcommands?
|
49
|
+
return 'last argument repeats' if last.repeat?
|
50
|
+
return 'new argument is required and last is optional' if
|
51
|
+
last.optional? && new_pos_arg.if_present(&:required?)
|
51
52
|
|
52
|
-
|
53
|
+
nil
|
53
54
|
end
|
54
55
|
|
55
56
|
def subcommands
|
@@ -65,7 +66,10 @@ module EacCli
|
|
65
66
|
private
|
66
67
|
|
67
68
|
def check_positional_blocked(new_pos_arg)
|
68
|
-
|
69
|
+
positional_arguments_blocked_reason(new_pos_arg).if_present do |v|
|
70
|
+
raise ::EacCli::Definition::Error, "Positional arguments are blocked: #{v}" \
|
71
|
+
" (New argument: #{new_pos_arg})"
|
72
|
+
end
|
69
73
|
end
|
70
74
|
|
71
75
|
def pos_set
|
@@ -26,7 +26,8 @@ module EacCli
|
|
26
26
|
common_constructor :value
|
27
27
|
|
28
28
|
def type
|
29
|
-
TYPES.find { |type| send("#{type}?") } ||
|
29
|
+
TYPES.find { |type| send("#{type}?") } ||
|
30
|
+
raise(::EacCli::Definition::Error, "Unknown type for \"#{value}\"")
|
30
31
|
end
|
31
32
|
|
32
33
|
def short?
|
@@ -16,7 +16,8 @@ module EacCli
|
|
16
16
|
def default_value
|
17
17
|
return super unless default_value?
|
18
18
|
|
19
|
-
raise
|
19
|
+
raise(::EacCli::Definition::Error,
|
20
|
+
"Unallowed default value for boolean options (Option: #{self})")
|
20
21
|
end
|
21
22
|
|
22
23
|
def default_default_value
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_cli/definition'
|
4
|
+
require 'eac_cli/definition/error'
|
4
5
|
require 'eac_cli/runner/class_runner'
|
5
6
|
|
6
7
|
module EacCli
|
@@ -21,7 +22,11 @@ module EacCli
|
|
21
22
|
|
22
23
|
def runner_definition(&block)
|
23
24
|
@runner_definition ||= super_runner_definition
|
24
|
-
|
25
|
+
begin
|
26
|
+
@runner_definition.instance_eval(&block) if block
|
27
|
+
rescue ::EacCli::Definition::Error => _e
|
28
|
+
raise ::EacCli::Definition::Error, "Definition error for #{self}"
|
29
|
+
end
|
25
30
|
@runner_definition
|
26
31
|
end
|
27
32
|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/parent'
|
5
|
+
require 'eac_cli/runner/context_responders/runner'
|
6
|
+
require 'eac_cli/runner/context_responders/runner_missing_method'
|
7
|
+
require 'eac_cli/runner/context_responders/set'
|
4
8
|
|
5
9
|
module EacCli
|
6
10
|
module Runner
|
@@ -17,10 +21,19 @@ module EacCli
|
|
17
21
|
|
18
22
|
# Call a method in the runner or in one of it ancestors.
|
19
23
|
def call(method_name, *args)
|
20
|
-
|
21
|
-
|
24
|
+
context_call_responder(method_name).call(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [EacCli::Runner::ContextResponders]
|
28
|
+
def context_call_responder(method_name)
|
29
|
+
::EacCli::Runner::ContextResponders::Set.new(self, method_name, %i[runner parent])
|
30
|
+
end
|
22
31
|
|
23
|
-
|
32
|
+
# @param method_name [Symbol]
|
33
|
+
# @return [EacCli::Runner::ContextResponders::Parent]
|
34
|
+
def runner_missing_method_responder(method_name)
|
35
|
+
::EacCli::Runner::ContextResponders::RunnerMissingMethod
|
36
|
+
.new(self, method_name)
|
24
37
|
end
|
25
38
|
|
26
39
|
# @param method_name [Symbol]
|
@@ -38,6 +51,12 @@ module EacCli
|
|
38
51
|
|
39
52
|
raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
|
40
53
|
end
|
54
|
+
|
55
|
+
# @param method_name [Symbol]
|
56
|
+
# @return [EacCli::Runner::ContextResponders::Parent]
|
57
|
+
def parent_responder(method_name)
|
58
|
+
::EacCli::Runner::ContextResponders::Parent.new(self, method_name)
|
59
|
+
end
|
41
60
|
end
|
42
61
|
end
|
43
62
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
module Runner
|
7
|
+
module ContextResponders
|
8
|
+
class Base
|
9
|
+
acts_as_abstract :call, :callable?
|
10
|
+
common_constructor :context, :method_name do
|
11
|
+
self.method_name = method_name.to_sym
|
12
|
+
end
|
13
|
+
delegate :parent, :runner, to: :context
|
14
|
+
|
15
|
+
def if_callable
|
16
|
+
return false unless callable?
|
17
|
+
|
18
|
+
yield(self)
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/base'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ContextResponders
|
9
|
+
class Parent < ::EacCli::Runner::ContextResponders::Base
|
10
|
+
def callable?
|
11
|
+
parent.if_present(false) do |v|
|
12
|
+
next true if v.respond_to?(method_name)
|
13
|
+
|
14
|
+
v.if_respond(:runner_context, false) { |w| w.parent_respond_to?(method_name) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(*args, &block)
|
19
|
+
return parent.runner_context.call(method_name, *args, &block) if
|
20
|
+
parent.respond_to?(:runner_context)
|
21
|
+
|
22
|
+
raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/base'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ContextResponders
|
9
|
+
class Runner < ::EacCli::Runner::ContextResponders::Base
|
10
|
+
def callable?
|
11
|
+
runner.respond_to?(method_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(*args, &block)
|
15
|
+
runner.send(method_name, *args, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/base'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ContextResponders
|
9
|
+
class RunnerMissingMethod < ::EacCli::Runner::ContextResponders::Base
|
10
|
+
def callable?
|
11
|
+
responder_runner.present?
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(*args, &block)
|
15
|
+
responder_runner.send(method_name, *args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def responder_runner
|
21
|
+
parent.if_present(nil) do |v|
|
22
|
+
next v if v.respond_to?(method_name) && v.for_context?(method_name)
|
23
|
+
|
24
|
+
v.if_respond(:runner_context, nil) do |w|
|
25
|
+
w.runner_missing_method_responder(method_name).send(__method__)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/base'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ContextResponders
|
9
|
+
class Set < ::EacCli::Runner::ContextResponders::Base
|
10
|
+
attr_reader :responders_names
|
11
|
+
|
12
|
+
def initialize(context, method_name, responders_names)
|
13
|
+
super(context, method_name)
|
14
|
+
@responders_names = responders_names
|
15
|
+
end
|
16
|
+
|
17
|
+
def callable?
|
18
|
+
responders_instances.any?(&:callable?)
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(*args, &block)
|
22
|
+
caller = responder_to_call
|
23
|
+
return caller.call(*args, &block) if caller
|
24
|
+
|
25
|
+
raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def responder_class(class_name)
|
31
|
+
::EacCli::Runner::ContextResponders.const_get(class_name.to_s.camelize)
|
32
|
+
end
|
33
|
+
|
34
|
+
def responders_instances
|
35
|
+
responders_names.lazy.map { |name| responder_class(name).new(context, method_name) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def responder_to_call
|
39
|
+
responders_instances.lazy.select(&:callable?).first
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/module_ancestors_variable/set'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ForContext
|
9
|
+
common_concern
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# @param methods_names [Enumerable<Symbol>]
|
13
|
+
# @return [void]
|
14
|
+
def for_context(*methods_names)
|
15
|
+
for_context_methods.merge(methods_names.map(&:to_sym))
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param method_name [Symbol]
|
19
|
+
# @return [Boolean]
|
20
|
+
def for_context?(method_name)
|
21
|
+
for_context_methods.include?(method_name.to_sym)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# @return [EacRubyUtils::ModuleAncestorsVariable::Set<Symbol>]
|
27
|
+
def for_context_methods
|
28
|
+
@for_context_methods ||=
|
29
|
+
::EacRubyUtils::ModuleAncestorsVariable::Set.new(self, __method__)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param method_name [Symbol]
|
34
|
+
# @return [Boolean]
|
35
|
+
def for_context?(method_name)
|
36
|
+
self.class.for_context?(method_name)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -30,13 +30,15 @@ module EacCli
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def respond_to_missing?(method, include_all = false)
|
33
|
-
runner_context.
|
33
|
+
runner_context.runner_missing_method_responder(method).callable? || super
|
34
34
|
end
|
35
35
|
|
36
36
|
def method_missing(method, *args, &block)
|
37
|
-
|
37
|
+
runner_context.runner_missing_method_responder(method).if_callable do |v|
|
38
|
+
return v.call(*args, &block)
|
39
|
+
end
|
38
40
|
|
39
|
-
|
41
|
+
super
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner'
|
4
|
+
|
5
|
+
::RSpec.describe ::EacCli::Runner do
|
6
|
+
let(:parent_runner_class) do
|
7
|
+
example = self
|
8
|
+
::Class.new do
|
9
|
+
include example.described_class
|
10
|
+
|
11
|
+
def self.name
|
12
|
+
'ParentRunnerClass'
|
13
|
+
end
|
14
|
+
|
15
|
+
for_context :method_for_context
|
16
|
+
|
17
|
+
def run; end
|
18
|
+
|
19
|
+
def method_for_context; end
|
20
|
+
|
21
|
+
def method_not_for_context; end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:child_runner_class_1) do
|
26
|
+
example = self
|
27
|
+
::Class.new do
|
28
|
+
include example.described_class
|
29
|
+
|
30
|
+
def self.name
|
31
|
+
'ChildRunnerClass1'
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
method_for_context
|
36
|
+
runner_context.call(:method_for_context)
|
37
|
+
runner_context.call(:method_not_for_context)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:child_runner_class_2) do
|
43
|
+
example = self
|
44
|
+
::Class.new do
|
45
|
+
include example.described_class
|
46
|
+
|
47
|
+
def self.name
|
48
|
+
'ChildRunnerClass2'
|
49
|
+
end
|
50
|
+
|
51
|
+
def run
|
52
|
+
method_not_for_context
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:parent_runner) { parent_runner_class.create }
|
58
|
+
let(:context_args) { [{ argv: [], parent: parent_runner }] }
|
59
|
+
let(:child_runner) { child_runner_class.create(*context_args) }
|
60
|
+
|
61
|
+
it { expect(parent_runner.for_context?(:method_for_context)).to eq(true) }
|
62
|
+
it { expect(parent_runner.for_context?(:method_not_for_context)).to eq(false) }
|
63
|
+
|
64
|
+
context 'when method is for context' do
|
65
|
+
let(:child_runner_class) { child_runner_class_1 }
|
66
|
+
|
67
|
+
it do
|
68
|
+
expect { child_runner.run }.not_to raise_error
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when method is not for context' do
|
73
|
+
let(:child_runner_class) { child_runner_class_2 }
|
74
|
+
|
75
|
+
it do
|
76
|
+
expect { child_runner.run }.to raise_error(::NameError)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.files = Dir['{lib}/**/*']
|
14
14
|
|
15
|
-
s.add_dependency 'avm-eac_ruby_base1', '~> 0.30', '>= 0.30.
|
16
|
-
s.add_dependency 'eac_cli', '~> 0.
|
15
|
+
s.add_dependency 'avm-eac_ruby_base1', '~> 0.30', '>= 0.30.3'
|
16
|
+
s.add_dependency 'eac_cli', '~> 0.35'
|
17
17
|
s.add_dependency 'eac_fs', '~> 0.16'
|
18
|
-
s.add_dependency 'eac_ruby_utils', '~> 0.
|
18
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.117'
|
19
19
|
|
20
20
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
|
21
21
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/node'
|
4
|
+
require 'eac_fs/contexts'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
require 'eac_ruby_utils/speaker'
|
7
|
+
|
8
|
+
module EacRubyBase0
|
9
|
+
module Runner
|
10
|
+
module Contexts
|
11
|
+
def on_context(&block)
|
12
|
+
top_block = block
|
13
|
+
available_contexts.each do |context|
|
14
|
+
next if context.object.any?
|
15
|
+
|
16
|
+
last_block = top_block
|
17
|
+
top_block = ::Proc.new { context.object.on(context.builder.call, &last_block) }
|
18
|
+
end
|
19
|
+
top_block.call
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# @return [Array<EacRubyUtils::Struct>]
|
25
|
+
def available_contexts
|
26
|
+
(filesystem_available_contexts + [
|
27
|
+
[:config, ::EacConfig::Node.context,
|
28
|
+
-> { runner_context.call(:application).build_config }],
|
29
|
+
[:speaker, ::EacRubyUtils::Speaker.context, -> { build_speaker }]
|
30
|
+
]).map { |row| available_context_row_to_struct(row) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def available_context_row_to_struct(row)
|
34
|
+
%i[type object builder].zip(row).to_h.to_struct
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_speaker
|
38
|
+
options = {}
|
39
|
+
options[:err_out] = ::StringIO.new if parsed.quiet?
|
40
|
+
options[:in_in] = ::EacCli::Speaker::InputBlocked.new if parsed.no_input?
|
41
|
+
::EacCli::Speaker.new(options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def filesystem_available_contexts
|
45
|
+
::EacFs::Contexts::TYPES.map do |type|
|
46
|
+
key = "fs_#{type}".to_sym
|
47
|
+
[key, ::EacFs::Contexts.send(type), -> { application.send("self_#{key}") }]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|