lib/fluxo/operation.rb in fluxo-0.2.0 vs lib/fluxo/operation.rb in fluxo-0.2.1
- old
+ new
@@ -40,11 +40,11 @@
end
# Calls step-method by step-method always passing the value to the next step
# If one of the methods is a failure stop the execution and return a result.
def __execute_flow__(steps: [], attributes: {})
- transient_attributes, transient_ids = attributes.dup, {ok: [], failure: [], exception: []}
+ transient_attributes, transient_ids = attributes.dup, Hash.new { |h, k| h[k] = [] }
__validate_attributes__(first_step: steps.first, attributes: transient_attributes)
result = nil
steps.unshift(:__validate__) if self.class.validations_proxy # add validate step before the first step
steps.each_with_index do |step, idx|
@@ -55,11 +55,11 @@
end
break unless result.success?
end
else
result = __wrap_result__(send(step, **transient_attributes))
- transient_ids.fetch(result.type).push(*result.ids)
+ transient_ids[result.type].push(*result.ids)
end
break unless result.success?
if steps[idx + 1]
@@ -68,10 +68,10 @@
old_attributes: transient_attributes,
next_step: steps[idx + 1]
)
end
end
- result.tap { |r| r.ids = transient_ids.fetch(r.type).uniq }
+ result.mutate(ids: transient_ids[result.type].uniq, operation: self)
end
# @param value_or_result_id [Any] The value for the result or the id when the result comes from block
def Success(value_or_result_id = nil)
attrs = {type: :ok, operation: self}