Class: Teckel::Operation::Runner
- Inherits:
-
Object
- Object
- Teckel::Operation::Runner
- Defined in:
- lib/teckel/operation/runner.rb
Overview
Note:
You shouldn’t need to call this explicitly. Use MyOperation.with() or MyOperation.call() instead.
The default implementation for executing a single Teckel::Operation
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #call(input = nil) ⇒ Object
-
#fail!(*args) ⇒ Object
protected
Halt any further execution with an error value.
-
#initialize(operation, settings = UNDEFINED) ⇒ Runner
constructor
A new instance of Runner.
-
#success!(*args) ⇒ Object
protected
Halt any further execution with a output value.
Constructor Details
#initialize(operation, settings = UNDEFINED) ⇒ Runner
Returns a new instance of Runner.
13 14 15 |
# File 'lib/teckel/operation/runner.rb', line 13 def initialize(operation, settings = UNDEFINED) @operation, @settings = operation, settings end |
Instance Attribute Details
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
16 17 18 |
# File 'lib/teckel/operation/runner.rb', line 16 def operation @operation end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
16 17 18 |
# File 'lib/teckel/operation/runner.rb', line 16 def settings @settings end |
Instance Method Details
#call(input = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/teckel/operation/runner.rb', line 18 def call(input = nil) catch(:failure) do out = catch(:success) do run operation.input_constructor.call(input) return nil # :sic!: return values need to go through +success!+ end return out end end |
#fail!(*args) ⇒ Object (protected)
Halt any further execution with an error value
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/teckel/operation/runner.rb', line 54 def fail!(*args) value = if args.size == 1 && operation.error === args.first # rubocop:disable Style/CaseEquality args.first else operation.error_constructor.call(*args) end throw :failure, operation.result_constructor.call(value, false) end |
#success!(*args) ⇒ Object (protected)
Halt any further execution with a output value
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/teckel/operation/runner.rb', line 39 def success!(*args) value = if args.size == 1 && operation.output === args.first # rubocop:disable Style/CaseEquality args.first else operation.output_constructor.call(*args) end throw :success, operation.result_constructor.call(value, true) end |