Module: Startback::Support::OperationRunner
- Included in:
- Event::Agent, Operation, Web::Api
- Defined in:
- lib/startback/support/operation_runner.rb
Overview
Support module for high-level architectural components that execute operations as part of their logic, see e.g. Web::Api.
This module contributes a ‘run` instance method that allows binding an operation with a world, and executing it while supporting around runners.
Example:
class HighLevelComponent
include Startback::Support::OperationRunner
def some_method
# Runs the operation passed after some binding
run SomeOperation.new
end
protected
# Overriden to inject some extra world
def operation_world(op)
super(op).merge({ hello: "world" })
end
# Execute this around op
around_run do |op, then_block|
puts "About to run #{op.inspect}"
then_block.call
end
# SomeClass#call will be called with the operation
# as first parameter and a block as continuation
around_run SomeClass.new
end
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(by) ⇒ Object
When included by a class/module, install the DSL methods.
Instance Method Summary collapse
-
#run(operation) ⇒ Object
Runs ‘operation`, taking care of binding it and executing hooks.
Class Method Details
.included(by) ⇒ Object
When included by a class/module, install the DSL methods
94 95 96 |
# File 'lib/startback/support/operation_runner.rb', line 94 def self.included(by) by.extend(ClassMethods) end |
Instance Method Details
#run(operation) ⇒ Object
Runs ‘operation`, taking care of binding it and executing hooks.
This method is NOT intended to be overriden. Use hooks and ‘operation_world` to impact default behavior.
103 104 105 106 107 108 109 110 |
# File 'lib/startback/support/operation_runner.rb', line 103 def run(operation) op_world = operation_world(operation) op_bound = operation.bind(op_world) _run_befores(op_bound) r = _run_with_arounds(op_bound, self.class.send(:arounds)) _run_afters(op_bound) r end |