Class: UltraMarathon::SubContext

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/ultra_marathon/sub_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(context, run_block) ⇒ SubContext

Returns a new instance of SubContext.



94
95
96
97
98
99
# File 'lib/ultra_marathon/sub_runner.rb', line 94

def initialize(context, run_block)
  @context = context
  # Ruby cannot marshal procs or lambdas, so we need to define a method.
  # Binding to self allows us to intercept logging calls.
  define_singleton_method(:call, &run_block.bind(self))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

If the original context responds, including private methods, delegate to it



103
104
105
106
107
108
109
# File 'lib/ultra_marathon/sub_runner.rb', line 103

def method_missing(method, *args, &block)
  if context.respond_to?(method, true)
    context.send(method, *args, &block)
  else
    raise NoMethodError.new("undefined local variable or method `#{method.to_s}' for #{context.class.name}")
  end
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



92
93
94
# File 'lib/ultra_marathon/sub_runner.rb', line 92

def context
  @context
end

#run_blockObject (readonly)

Returns the value of attribute run_block.



92
93
94
# File 'lib/ultra_marathon/sub_runner.rb', line 92

def run_block
  @run_block
end