Class: BusinessFlow::Step
- Inherits:
-
Object
- Object
- BusinessFlow::Step
show all
- Defined in:
- lib/business_flow/step.rb
Overview
Step is a conditional callable which can marshal its own inputs, and returns a value which can marshal errors and outputs into a given object.
Defined Under Namespace
Classes: ConditionFailedResult, ConditionList, Inputs, Options, Result, ResultFactory
Instance Method Summary
collapse
Constructor Details
#initialize(callable, opts) ⇒ Step
Returns a new instance of Step.
155
156
157
158
159
160
161
|
# File 'lib/business_flow/step.rb', line 155
def initialize(callable, opts)
@callable = callable
opts = Options.new(opts)
@input_object = opts.input_object
@result_factory = opts.result_factory
@condition = opts.condition
end
|
Instance Method Details
#call(parameter_source) ⇒ Object
163
164
165
166
167
168
169
170
|
# File 'lib/business_flow/step.rb', line 163
def call(parameter_source)
parameters = @input_object.parameters_from_source(parameter_source)
if @condition.call(parameter_source, parameters)
@result_factory.result(@callable.call(parameter_source, parameters))
else
ConditionFailedResult.new
end
end
|
172
173
174
|
# File 'lib/business_flow/step.rb', line 172
def inputs
@input_object.inputs
end
|
#outputs ⇒ Object
176
177
178
|
# File 'lib/business_flow/step.rb', line 176
def outputs
@result_factory.outputs
end
|
#to_s ⇒ Object
180
181
182
|
# File 'lib/business_flow/step.rb', line 180
def to_s
@callable.to_s
end
|