Class: EacCli::Runner::Context
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#program_name ⇒ Object
readonly
Returns the value of attribute program_name.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
-
#call(method_name, *args, &block) ⇒ Object
Call a method in the runner or in one of it ancestors.
- #context_call_responder(method_name) ⇒ EacCli::Runner::ContextResponders
-
#initialize(runner, *context_args) ⇒ Context
constructor
A new instance of Context.
- #parent_call(method_name, *args, &block) ⇒ Object
- #parent_respond_to?(method_name) ⇒ Boolean
- #parent_responder(method_name) ⇒ EacCli::Runner::ContextResponders::Parent
- #runner_missing_method_responder(method_name) ⇒ EacCli::Runner::ContextResponders::Parent
Constructor Details
#initialize(runner, *context_args) ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 13 14 |
# File 'lib/eac_cli/runner/context.rb', line 8 def initialize(runner, *context_args) = context_args. @argv = (context_args[0] || .delete(:argv) || ARGV).dup.freeze @parent = context_args[1] || .delete(:parent) @program_name = .delete(:program_name) @runner = runner end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
6 7 8 |
# File 'lib/eac_cli/runner/context.rb', line 6 def argv @argv end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/eac_cli/runner/context.rb', line 6 def parent @parent end |
#program_name ⇒ Object (readonly)
Returns the value of attribute program_name.
6 7 8 |
# File 'lib/eac_cli/runner/context.rb', line 6 def program_name @program_name end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
6 7 8 |
# File 'lib/eac_cli/runner/context.rb', line 6 def runner @runner end |
Instance Method Details
#call(method_name, *args, &block) ⇒ Object
Call a method in the runner or in one of it ancestors.
17 18 19 |
# File 'lib/eac_cli/runner/context.rb', line 17 def call(method_name, *args, &block) context_call_responder(method_name).call(*args, &block) end |
#context_call_responder(method_name) ⇒ EacCli::Runner::ContextResponders
22 23 24 |
# File 'lib/eac_cli/runner/context.rb', line 22 def context_call_responder(method_name) ::EacCli::Runner::ContextResponders::Set.new(self, method_name, %i[runner parent]) end |
#parent_call(method_name, *args, &block) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/eac_cli/runner/context.rb', line 43 def parent_call(method_name, *args, &block) return parent.runner_context.call(method_name, *args, &block) if parent.respond_to?(:runner_context) raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})" end |
#parent_respond_to?(method_name) ⇒ Boolean
35 36 37 38 39 40 41 |
# File 'lib/eac_cli/runner/context.rb', line 35 def parent_respond_to?(method_name) parent.if_present(false) do |v| next true if v.respond_to?(method_name) v.if_respond(:runner_context, false) { |w| w.parent_respond_to?(method_name) } end end |
#parent_responder(method_name) ⇒ EacCli::Runner::ContextResponders::Parent
52 53 54 |
# File 'lib/eac_cli/runner/context.rb', line 52 def parent_responder(method_name) ::EacCli::Runner::ContextResponders::Parent.new(self, method_name) end |
#runner_missing_method_responder(method_name) ⇒ EacCli::Runner::ContextResponders::Parent
28 29 30 31 |
# File 'lib/eac_cli/runner/context.rb', line 28 def runner_missing_method_responder(method_name) ::EacCli::Runner::ContextResponders::RunnerMissingMethod .new(self, method_name) end |