Class: OmniService::Shortcut

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

Overview

Enables early pipeline exit on success. Used for idempotency and guard clauses.

On success: marks result with shortcut flag, causing Sequence to exit immediately. On failure: returns empty success, allowing pipeline to continue.

Examples:

Idempotent post creation

sequence(
  shortcut(find_existing_post),  # Found? Exit with existing post
  validate_params,                # Not found? Continue creation
  create_post
)

Guard clause

sequence(
  shortcut(check_already_subscribed),  # Already subscribed? Done
  validate_subscription,
  create_subscription
)

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/shortcut.rb', line 30

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

  if result.success?
    result.merge(shortcut: component)
  else
    OmniService::Result.build(self, params:, context:)
  end
end

#signatureObject



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

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