Class: BusinessFlow::Step
- Inherits:
-
Object
- Object
- BusinessFlow::Step
- 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
Constant Summary collapse
- CONDITION_FAILED =
ConditionFailedResult.new.freeze
Instance Method Summary collapse
-
#call(parameter_source) ⇒ Object
This will show up as not covered in coverage reports, because it is dynamically redefined by #update_call_method below.
-
#initialize(callable, opts) ⇒ Step
constructor
A new instance of Step.
- #inputs ⇒ Object
- #output_fields ⇒ Object
- #outputs ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(callable, opts) ⇒ Step
Returns a new instance of Step.
192 193 194 195 196 197 198 199 200 |
# File 'lib/business_flow/step.rb', line 192 def initialize(callable, opts) @callable = callable opts = Options.new(opts) @input_object = opts.input_object @result_factory = opts.result_factory @condition = opts.condition update_call_method end |
Instance Method Details
#call(parameter_source) ⇒ Object
This will show up as not covered in coverage reports, because it is dynamically redefined by #update_call_method below.
204 205 206 207 208 209 210 211 212 |
# File 'lib/business_flow/step.rb', line 204 def call(parameter_source) parameters = @input_object.parameters_from_source(parameter_source) if !@condition || @condition.call(parameter_source, parameters) @result_factory.result(@callable.call(parameter_source, parameters), parameter_source) else CONDITION_FAILED end end |
#inputs ⇒ Object
214 215 216 |
# File 'lib/business_flow/step.rb', line 214 def inputs @input_object.inputs end |
#output_fields ⇒ Object
222 223 224 225 226 |
# File 'lib/business_flow/step.rb', line 222 def output_fields return [] unless outputs outputs.values.select { |field| field.is_a?(Symbol) } end |
#outputs ⇒ Object
218 219 220 |
# File 'lib/business_flow/step.rb', line 218 def outputs @result_factory.outputs end |
#to_s ⇒ Object
228 229 230 |
# File 'lib/business_flow/step.rb', line 228 def to_s @callable.to_s end |