Sha256: 14d824eee2d4a3ab78769c2cedc3fd94230329c85ec9e5c8f4e191046a81e207
Contents?: true
Size: 874 Bytes
Versions: 1
Compression:
Stored size: 874 Bytes
Contents
# frozen_string_literal: true module Micro module Service class Pipeline INVALID_COLLECTION = 'argument must be a collection of `Micro::Service::Base` classes'.freeze def self.[](*services) new(services) end 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| break result if result.failure? service.call(result.value) end end private def validate!(services) Array(services).tap do |collection| if collection.any? { |klass| !(klass < ::Micro::Service::Base) } raise ArgumentError, INVALID_COLLECTION end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
u-service-0.4.0 | lib/micro/service/pipeline.rb |