class BusinessFlow::Step
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.
Constants
- CONDITION_FAILED
- Options
Responsible for creating objects based on our input options
- PARAMETERS_NO_INPUT
- PARAMETERS_WITH_INPUT
- ResultFactory
Manage creating results for our step
- WITHOUT_CONDITION
- WITH_CONDITION
Public Class Methods
new(callable, opts)
click to toggle source
# File lib/business_flow/step.rb, line 194 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
Public Instance Methods
call(parameter_source)
click to toggle source
This will show up as not covered in coverage reports, because it is dynamically redefined by update_call_method
below.
# File lib/business_flow/step.rb, line 206 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()
click to toggle source
# File lib/business_flow/step.rb, line 216 def inputs @input_object.inputs end
output_fields()
click to toggle source
# File lib/business_flow/step.rb, line 224 def output_fields return [] unless outputs outputs.values.select { |field| field.is_a?(Symbol) } end
outputs()
click to toggle source
# File lib/business_flow/step.rb, line 220 def outputs @result_factory.outputs end
to_s()
click to toggle source
# File lib/business_flow/step.rb, line 229 def to_s @callable.to_s end
Private Instance Methods
update_call_method()
click to toggle source
# File lib/business_flow/step.rb, line 250 def update_call_method params = @input_object ? PARAMETERS_WITH_INPUT : PARAMETERS_NO_INPUT code = %( def call(parameter_source) parameters = #{params} #{@condition ? WITH_CONDITION : WITHOUT_CONDITION} end ) instance_eval code end