Class: Rainman::Runner
- Inherits:
-
Object
- Object
- Rainman::Runner
- Defined in:
- lib/rainman/runner.rb
Overview
The Runner class delegates actions to handlers. It runs validations before executing the action.
Examples
Runner.new(current_handler_instance).tap do |r|
r.transfer
end
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Public: Gets the handler Class.
Instance Method Summary collapse
-
#execute(context, method, *args, &block) ⇒ Object
Public: Delegates the given method to the handler.
-
#initialize(handler) ⇒ Runner
constructor
Public: Initialize a runner.
-
#method_missing(method, *args, &block) ⇒ Object
Internal: Method missing hook used to proxy methods to a handler.
-
#name ⇒ Object
Public: Get the Symbol name of the handler.
-
#parent_klass ⇒ Object
Public: Get the handler’s parent_klass.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Internal: Method missing hook used to proxy methods to a handler.
method - The missing method name. args - Arguments to be supplied to the method (optional). block - Block to be supplied to the method (optional).
Raises NameError if handler does not respond to method.
Returns the value of execute.
71 72 73 74 75 76 77 78 79 |
# File 'lib/rainman/runner.rb', line 71 def method_missing(method, *args, &block) if handler.respond_to?(method) execute(handler, method, *args, &block) elsif parent_klass.respond_to?(method) execute(parent_klass, method, *args, &block) else super end end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Public: Gets the handler Class.
12 13 14 |
# File 'lib/rainman/runner.rb', line 12 def handler @handler end |
Instance Method Details
#execute(context, method, *args, &block) ⇒ Object
Public: Delegates the given method to the handler.
context - Set the context for the method (class/instance) method - The method to send to the handler. args - Arguments to be supplied to the method (optional). block - Block to be supplied to the method (optional).
Examples
execute(handler, :register)
execute(handler.parent_class, :register, { params: [] })
execute(handler, :register, :one, :argument) do
# some code
end
Raises MissingParameter if validation fails due to missing parameters.
Returns the result of the handler action.
57 58 59 60 |
# File 'lib/rainman/runner.rb', line 57 def execute(context, method, *args, &block) # verify params here context.send(method, *args, &block) end |
#name ⇒ Object
Public: Get the Symbol name of the handler.
Returns a Symbol.
28 29 30 |
# File 'lib/rainman/runner.rb', line 28 def name handler.class.handler_name end |
#parent_klass ⇒ Object
Public: Get the handler’s parent_klass
Returns Rainman::Driver.self
35 36 37 |
# File 'lib/rainman/runner.rb', line 35 def parent_klass handler.class.parent_klass end |