Class: OmniService::Optional

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Includes:
Strict
Defined in:
lib/omni_service/optional.rb

Overview

Swallows component failures, returning empty success instead. Useful for non-critical operations that shouldn’t block the pipeline.

On success: returns component result unchanged. On failure: returns Success({}) with empty context, discarding errors.

Examples:

Optional profile enrichment

sequence(
  create_user,
  optional(fetch_avatar_from_gravatar),  # Failure won't stop pipeline
  send_welcome_email
)

Optional cache warming

sequence(
  update_post,
  optional(warm_cache)  # Cache failure is acceptable
)

Instance Method Summary collapse

Methods included from Strict

#call!

Instance Method Details

#call(*params, **context) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/omni_service/optional.rb', line 30

def call(*params, **context)
  result = component_wrapper.call(*params, **context)

  if result.success?
    result
  else
    OmniService::Result.build(self, params: result.params, context: {})
  end
end

#signatureObject



40
41
42
# File 'lib/omni_service/optional.rb', line 40

def signature
  @signature ||= [component_wrapper.signature.first, true]
end