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.



10
11
12
13
14
15
16
# File 'lib/eac_cli/runner/context.rb', line 10

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.



8
9
10
# File 'lib/eac_cli/runner/context.rb', line 8

def argv
  @argv
end

#parentObject (readonly)

Returns the value of attribute parent.



8
9
10
# File 'lib/eac_cli/runner/context.rb', line 8

def parent
  @parent
end

#program_nameObject (readonly)

Returns the value of attribute program_name.



8
9
10
# File 'lib/eac_cli/runner/context.rb', line 8

def program_name
  @program_name
end

#runnerObject (readonly)

Returns the value of attribute runner.



8
9
10
# File 'lib/eac_cli/runner/context.rb', line 8

def runner
  @runner
end

Instance Method Details

#call(method_name, *args) ⇒ Object

Call a method in the runner or in one of it ancestors.

Raises:

  • (::NameError)


19
20
21
22
23
24
# File 'lib/eac_cli/runner/context.rb', line 19

def call(method_name, *args)
  return runner.send(method_name, *args) if runner.respond_to?(method_name)
  return parent_call(method_name, *args) if parent.present?

  raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
end