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

Instance Method Summary collapse

Constructor Details

#initialize(callable, opts) ⇒ Step

Returns a new instance of Step.



169
170
171
172
173
174
175
# File 'lib/business_flow/step.rb', line 169

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



177
178
179
180
181
182
183
184
185
# File 'lib/business_flow/step.rb', line 177

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),
                           parameter_source)
  else
    ConditionFailedResult.new
  end
end

#inputsObject



187
188
189
# File 'lib/business_flow/step.rb', line 187

def inputs
  @input_object.inputs
end

#outputsObject



191
192
193
# File 'lib/business_flow/step.rb', line 191

def outputs
  @result_factory.outputs
end

#to_sObject



195
196
197
# File 'lib/business_flow/step.rb', line 195

def to_s
  @callable.to_s
end