eac_tools 0.65.1 → 0.67.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +32 -32
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +3 -3
  5. data/sub/avm/lib/avm/data/clearer.rb +20 -0
  6. data/sub/avm/lib/avm/data/package/base_performer.rb +38 -0
  7. data/sub/avm/lib/avm/data/package/clear.rb +22 -0
  8. data/sub/avm/lib/avm/data/package/dump.rb +0 -10
  9. data/sub/avm/lib/avm/data/package.rb +8 -1
  10. data/sub/avm/lib/avm/data/performer.rb +49 -0
  11. data/sub/avm/lib/avm/docker/runner.rb +0 -4
  12. data/sub/avm/lib/avm/instances/base/auto_values/data.rb +1 -2
  13. data/sub/avm/lib/avm/instances/base.rb +10 -0
  14. data/sub/avm/lib/avm/instances/runner.rb +1 -1
  15. data/sub/avm/lib/avm/sources/runner.rb +2 -0
  16. data/sub/avm/lib/avm/version.rb +1 -1
  17. data/sub/avm-eac_ubuntu_base0/avm-eac_ubuntu_base0.gemspec +3 -3
  18. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/runners/base.rb +2 -0
  19. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/version.rb +1 -1
  20. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +4 -4
  21. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/provider.rb +2 -2
  22. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/base.rb +0 -10
  23. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  24. data/sub/avm-tools/avm-tools.gemspec +4 -4
  25. data/sub/avm-tools/lib/avm/tools/runner/instance/data/clear.rb +18 -0
  26. data/sub/avm-tools/lib/avm/tools/runner/instance/data/dump.rb +1 -5
  27. data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/clear.rb +1 -5
  28. data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/dump.rb +2 -2
  29. data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/load.rb +1 -1
  30. data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit.rb +3 -1
  31. data/sub/avm-tools/lib/avm/tools/runner/instance/data.rb +7 -0
  32. data/sub/avm-tools/lib/avm/tools/runner/launcher.rb +0 -1
  33. data/sub/avm-tools/lib/avm/tools/runner/launcher_stereotypes/list.rb +0 -1
  34. data/sub/avm-tools/lib/avm/tools/runner_with/include_exclude.rb +23 -0
  35. data/sub/avm-tools/lib/avm/tools/runner_with/instance_data_clear.rb +30 -0
  36. data/sub/avm-tools/lib/avm/tools/runner_with.rb +11 -0
  37. data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
  38. data/sub/eac_cli/eac_cli.gemspec +1 -1
  39. data/sub/eac_cli/lib/eac_cli/definition/alternative.rb +11 -7
  40. data/sub/eac_cli/lib/eac_cli/definition/base_option/initialize_args_parser.rb +2 -1
  41. data/sub/eac_cli/lib/eac_cli/definition/base_option.rb +1 -1
  42. data/sub/eac_cli/lib/eac_cli/definition/boolean_option.rb +2 -1
  43. data/sub/eac_cli/lib/eac_cli/definition/error.rb +8 -0
  44. data/sub/eac_cli/lib/eac_cli/runner/after_class_methods.rb +6 -1
  45. data/sub/eac_cli/lib/eac_cli/runner/context.rb +29 -7
  46. data/sub/eac_cli/lib/eac_cli/runner/context_responders/base.rb +24 -0
  47. data/sub/eac_cli/lib/eac_cli/runner/context_responders/parent.rb +27 -0
  48. data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner.rb +20 -0
  49. data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner_missing_method.rb +32 -0
  50. data/sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb +44 -0
  51. data/sub/eac_cli/lib/eac_cli/runner/context_responders.rb +11 -0
  52. data/sub/eac_cli/lib/eac_cli/runner/for_context.rb +40 -0
  53. data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +5 -3
  54. data/sub/eac_cli/lib/eac_cli/runner.rb +1 -0
  55. data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
  56. data/sub/eac_cli/spec/lib/eac_cli/runner/for_context_spec.rb +79 -0
  57. data/sub/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +11 -1
  58. data/sub/eac_ruby_base0/eac_ruby_base0.gemspec +3 -3
  59. data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb +52 -0
  60. data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner/prepend.rb +17 -4
  61. data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +1 -39
  62. data/sub/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  63. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_abstract.rb +17 -6
  64. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/array_accessor.rb +25 -0
  65. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb +57 -0
  66. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/boolean_accessor.rb +3 -3
  67. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/class_methods.rb +2 -2
  68. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/common_accessor.rb +5 -5
  69. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable/array_accessor.rb → acts_as_immutable/enumerable_accessor.rb} +11 -8
  70. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor.rb +5 -5
  71. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/instance_methods.rb +1 -1
  72. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/set_accessor.rb +25 -0
  73. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable.rb → acts_as_immutable.rb} +1 -1
  74. data/sub/eac_ruby_utils/lib/eac_ruby_utils/enumerables_methods.rb +42 -0
  75. data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/base.rb +34 -0
  76. data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/hash.rb +20 -0
  77. data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/set.rb +19 -0
  78. data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable.rb +9 -0
  79. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/acts_as_immutable.rb +10 -0
  80. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +3 -2
  81. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +9 -0
  82. data/sub/eac_ruby_utils/lib/eac_ruby_utils/unimplemented_method_error.rb +6 -0
  83. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  84. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_abstract_spec.rb +73 -7
  85. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{immutable → acts_as_immutable}/array_accessor_spec.rb +11 -3
  86. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_immutable/common_accessor_spec.rb +57 -0
  87. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor_spec.rb +3 -3
  88. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_immutable/set_accessor_spec.rb +43 -0
  89. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/enumerables_methods_spec.rb +50 -0
  90. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/module_ancestors_variable/hash_spec.rb +57 -0
  91. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/module_ancestors_variable/set_spec.rb +57 -0
  92. metadata +56 -20
  93. data/sub/avm-tools/lib/avm/projects/stereotypes.rb +0 -15
  94. data/sub/avm-tools/lib/avm/projects.rb +0 -9
  95. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +0 -23
@@ -13,6 +13,13 @@ module Avm
13
13
  desc 'Data utilities for EacRailsBase0 instances.'
14
14
  subcommands
15
15
  end
16
+
17
+ for_context :data_owner
18
+
19
+ # @return [Avm::Instances::Data::Package]
20
+ def data_owner
21
+ instance.data_package
22
+ end
16
23
  end
17
24
  end
18
25
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/tools/core_ext'
4
- require 'avm/projects/stereotypes'
5
4
 
6
5
  module Avm
7
6
  module Tools
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/launcher/stereotype'
4
- require 'avm/projects/stereotypes'
5
4
  require 'avm/tools/core_ext'
6
5
 
7
6
  module Avm
@@ -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
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/clearer'
4
+ require 'eac_cli/core_ext'
5
+ require 'eac_cli/runner'
6
+
7
+ module Avm
8
+ module Tools
9
+ module RunnerWith
10
+ module InstanceDataClear
11
+ common_concern do
12
+ enable_simple_cache
13
+ include ::EacCli::Runner
14
+ end
15
+
16
+ def run
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
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Tools
7
+ module RunnerWith
8
+ require_sub __FILE__, require_mode: :kernel
9
+ end
10
+ end
11
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.147.0'
5
+ VERSION = '0.149.0'
6
6
  end
7
7
  end
@@ -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.114'
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 positional_arguments_blocked?(new_pos_arg)
45
+ def positional_arguments_blocked_reason(new_pos_arg)
46
46
  last = pos_set.last
47
- return false unless last
48
- return true if subcommands?
49
- return true if last.repeat?
50
- return true if last.optional? && new_pos_arg.if_present(&:required?)
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
- false
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
- raise 'Positional arguments are blocked' if positional_arguments_blocked?(new_pos_arg)
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}?") } || raise("Unknown type for \"#{value}\"")
29
+ TYPES.find { |type| send("#{type}?") } ||
30
+ raise(::EacCli::Definition::Error, "Unknown type for \"#{value}\"")
30
31
  end
31
32
 
32
33
  def short?
@@ -42,7 +42,7 @@ module EacCli
42
42
  v.to_s.if_present { |vv| return vv.variableize.to_sym }
43
43
  end
44
44
 
45
- raise 'No short or long option to build identifier'
45
+ raise(::EacCli::Definition::Error, 'No short or long option to build identifier')
46
46
  end
47
47
 
48
48
  def repeat?
@@ -16,7 +16,8 @@ module EacCli
16
16
  def default_value
17
17
  return super unless default_value?
18
18
 
19
- raise "Unallowed default value for boolean options (Option: #{self})"
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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class Definition
5
+ class Error < ::StandardError
6
+ end
7
+ end
8
+ end
@@ -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
- @runner_definition.instance_eval(&block) if block
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,24 +21,42 @@ 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
- return runner.send(method_name, *args) if runner.respond_to?(method_name)
21
- return parent_call(method_name, *args) if parent.present?
24
+ context_call_responder(method_name).call(*args)
25
+ end
22
26
 
23
- raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
27
+ # @return [EacCli::Runner::ContextResponders]
28
+ def context_call_responder(method_name)
29
+ ::EacCli::Runner::ContextResponders::Set.new(self, method_name, %i[runner parent])
24
30
  end
25
31
 
26
- def respond_to_call?((method_name))
27
- parent.respond_to?(:runner_context) && parent.runner_context.respond_to_call?(method_name)
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)
28
37
  end
29
38
 
30
- protected
39
+ # @param method_name [Symbol]
40
+ # @return [Boolean]
41
+ def parent_respond_to?(method_name)
42
+ parent.if_present(false) do |v|
43
+ next true if v.respond_to?(method_name)
44
+
45
+ v.if_respond(:runner_context, false) { |w| w.parent_respond_to?(method_name) }
46
+ end
47
+ end
31
48
 
32
49
  def parent_call(method_name, *args)
33
- return parent.context(method_name, *args) if parent.respond_to?(:context)
34
50
  return parent.runner_context.call(method_name, *args) if parent.respond_to?(:runner_context)
35
51
 
36
52
  raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
37
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
38
60
  end
39
61
  end
40
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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ module Runner
7
+ module ContextResponders
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ 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.respond_to_call?(method) || super
33
+ runner_context.runner_missing_method_responder(method).callable? || super
34
34
  end
35
35
 
36
36
  def method_missing(method, *args, &block)
37
- return super unless runner_context.respond_to_call?(method)
37
+ runner_context.runner_missing_method_responder(method).if_callable do |v|
38
+ return v.call(*args, &block)
39
+ end
38
40
 
39
- runner_context.call(method, *args, &block)
41
+ super
40
42
  end
41
43
  end
42
44
  end
@@ -42,6 +42,7 @@ module EacCli
42
42
 
43
43
  extend AfterClassMethods
44
44
  include InstanceMethods
45
+ include ::EacCli::Runner::ForContext
45
46
  include ActiveSupport::Callbacks
46
47
  define_callbacks :run
47
48
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.33.0'
4
+ VERSION = '0.35.0'
5
5
  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
@@ -19,6 +19,9 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
19
19
  end
20
20
 
21
21
  delegate :root_var, to: :parsed
22
+ for_context :method_in_parent_runner
23
+
24
+ def method_in_parent_runner; end
22
25
  end
23
26
  end
24
27
 
@@ -31,7 +34,10 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
31
34
  pos_arg :child_var
32
35
  end
33
36
 
34
- def run; end
37
+ def run
38
+ runner_context.call(:method_in_parent_runner)
39
+ method_in_parent_runner
40
+ end
35
41
  end
36
42
  end
37
43
 
@@ -45,6 +51,10 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
45
51
  it { expect(instance.parsed.subcommand_args).to eq(%w[--child-opt 456]) }
46
52
  it { expect(instance.subcommand_runner.parsed.child_opt).to eq(true) }
47
53
  it { expect(instance.subcommand_runner.parsed.child_var).to eq('456') }
54
+
55
+ it do
56
+ expect { instance.run_run }.not_to raise_error
57
+ end
48
58
  end
49
59
 
50
60
  context 'when subcommand is not supplied' do
@@ -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.2'
16
- s.add_dependency 'eac_cli', '~> 0.31'
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.112'
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