lib/micro/service/pipeline.rb in u-service-0.4.0 vs lib/micro/service/pipeline.rb in u-service-0.5.0

- old
+ new

@@ -13,13 +13,11 @@ def initialize(services) @services = validate!(services) end def call(arg={}) - initial_result = Micro::Service::Result::Success(value: arg) - - @services.reduce(initial_result) do |result, service| + @services.reduce(initial_result(arg)) do |result, service| break result if result.failure? service.call(result.value) end end @@ -29,9 +27,14 @@ Array(services).tap do |collection| if collection.any? { |klass| !(klass < ::Micro::Service::Base) } raise ArgumentError, INVALID_COLLECTION end end + end + + def initial_result(arg) + return arg if arg.is_a?(Micro::Service::Result) + Micro::Service::Result::Success(value: arg) end end end end