Class: UltraMarathon::SubContext
- Inherits:
-
Object
- Object
- UltraMarathon::SubContext
- Includes:
- Logging
- Defined in:
- lib/ultra_marathon/sub_runner.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#run_block ⇒ Object
readonly
Returns the value of attribute run_block.
Instance Method Summary collapse
-
#initialize(context, run_block) ⇒ SubContext
constructor
A new instance of SubContext.
-
#method_missing(method, *args, &block) ⇒ Object
If the original context responds, including private methods, delegate to it.
Methods included from Logging
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
#context ⇒ Object (readonly)
Returns the value of attribute context.
92 93 94 |
# File 'lib/ultra_marathon/sub_runner.rb', line 92 def context @context end |
#run_block ⇒ Object (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 |