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.
14 15 16 17 18 19 20 |
# File 'lib/eac_cli/runner/context.rb', line 14 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.
12 13 14 |
# File 'lib/eac_cli/runner/context.rb', line 12 def argv @argv end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
12 13 14 |
# File 'lib/eac_cli/runner/context.rb', line 12 def parent @parent end |
#program_name ⇒ Object (readonly)
Returns the value of attribute program_name.
12 13 14 |
# File 'lib/eac_cli/runner/context.rb', line 12 def program_name @program_name end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
12 13 14 |
# File 'lib/eac_cli/runner/context.rb', line 12 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.
23 24 25 |
# File 'lib/eac_cli/runner/context.rb', line 23 def call(method_name, *args, &block) context_call_responder(method_name).call(*args, &block) end |
#context_call_responder(method_name) ⇒ EacCli::Runner::ContextResponders
28 29 30 |
# File 'lib/eac_cli/runner/context.rb', line 28 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
49 50 51 52 53 54 |
# File 'lib/eac_cli/runner/context.rb', line 49 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
41 42 43 44 45 46 47 |
# File 'lib/eac_cli/runner/context.rb', line 41 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
58 59 60 |
# File 'lib/eac_cli/runner/context.rb', line 58 def parent_responder(method_name) ::EacCli::Runner::ContextResponders::Parent.new(self, method_name) end |
#runner_missing_method_responder(method_name) ⇒ EacCli::Runner::ContextResponders::Parent
34 35 36 37 |
# File 'lib/eac_cli/runner/context.rb', line 34 def runner_missing_method_responder(method_name) ::EacCli::Runner::ContextResponders::RunnerMissingMethod .new(self, method_name) end |