Class: OmniService::Sequence
- Inherits:
-
Object
- Object
- OmniService::Sequence
- Extended by:
- Dry::Initializer
- Includes:
- Strict
- Defined in:
- lib/omni_service/sequence.rb
Overview
Executes components sequentially, short-circuiting on first failure or shortcut. Context accumulates across components; each receives merged context from previous.
Instance Method Summary collapse
- #call(*params, **context) ⇒ Object
-
#initialize(*args) ⇒ Sequence
constructor
A new instance of Sequence.
- #signature ⇒ Object
Methods included from Strict
Constructor Details
#initialize(*args) ⇒ Sequence
Returns a new instance of Sequence.
29 30 31 |
# File 'lib/omni_service/sequence.rb', line 29 def initialize(*args, **) super(args.flatten(1), **) end |
Instance Method Details
#call(*params, **context) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/omni_service/sequence.rb', line 33 def call(*params, **context) component_wrappers.inject(OmniService::Result.build(self, params:, context:)) do |result, component| break result if result.failure? || result.shortcut? result.merge(component.call(*result.params, **result.context)) end end |
#signature ⇒ Object
41 42 43 44 45 46 |
# File 'lib/omni_service/sequence.rb', line 41 def signature @signature ||= begin param_counts = component_wrappers.map { |component| component.signature.first } [param_counts.all? ? param_counts.max : nil, true] end end |