Class: Micro::Service::Pipeline::Reducer
- Inherits:
-
Object
- Object
- Micro::Service::Pipeline::Reducer
- Defined in:
- lib/micro/service/pipeline.rb
Constant Summary collapse
- INVALID_SERVICES =
'argument must be a collection of `Micro::Service::Base` classes'.freeze
Instance Attribute Summary collapse
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Class Method Summary collapse
Instance Method Summary collapse
- #>>(arg) ⇒ Object
- #call(arg = {}) ⇒ Object
-
#initialize(services) ⇒ Reducer
constructor
A new instance of Reducer.
Constructor Details
#initialize(services) ⇒ Reducer
Returns a new instance of Reducer.
26 27 28 |
# File 'lib/micro/service/pipeline.rb', line 26 def initialize(services) @services = services end |
Instance Attribute Details
#services ⇒ Object (readonly)
Returns the value of attribute services.
7 8 9 |
# File 'lib/micro/service/pipeline.rb', line 7 def services @services end |
Class Method Details
.build(args) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/micro/service/pipeline.rb', line 18 def self.build(args) services = Array(args).flat_map { |arg| map_services(arg) } raise ArgumentError, INVALID_SERVICES if services.any? { |klass| !(klass < ::Micro::Service::Base) } new(services) end |
Instance Method Details
#>>(arg) ⇒ Object
37 38 39 |
# File 'lib/micro/service/pipeline.rb', line 37 def >>(arg) Reducer.build(services + self.class.map_services(arg)) end |
#call(arg = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/micro/service/pipeline.rb', line 30 def call(arg={}) @services.reduce(initial_result(arg)) do |result, service| break result if result.failure? service.call(result.value) end end |