Class: EacCli::Runner::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_cli/runner/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
  options = context_args.extract_options!
  @argv = (context_args[0] || options.delete(:argv) || ARGV).dup.freeze
  @parent = context_args[1] || options.delete(:parent)
  @program_name = options.delete(:program_name)
  @runner = runner
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



12
13
14
# File 'lib/eac_cli/runner/context.rb', line 12

def argv
  @argv
end

#parentObject (readonly)

Returns the value of attribute parent.



12
13
14
# File 'lib/eac_cli/runner/context.rb', line 12

def parent
  @parent
end

#program_nameObject (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

#runnerObject (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

Parameters:

  • method_name (Symbol)

Returns:

  • (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

Parameters:

  • method_name (Symbol)

Returns:



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

Parameters:

  • method_name (Symbol)

Returns:



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