Class: BusinessFlow::Step

Inherits:
Object
  • Object
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

Constant Summary collapse

CONDITION_FAILED =
ConditionFailedResult.new.freeze

Instance Method Summary collapse

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

#inputsObject



214
215
216
# File 'lib/business_flow/step.rb', line 214

def inputs
  @input_object.inputs
end

#output_fieldsObject



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

#outputsObject



218
219
220
# File 'lib/business_flow/step.rb', line 218

def outputs
  @result_factory.outputs
end

#to_sObject



228
229
230
# File 'lib/business_flow/step.rb', line 228

def to_s
  @callable.to_s
end