Class: OmniService::Namespace

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

Overview

Scopes component execution under a namespace key.

Behavior:

  • Extracts params from params (disable with shared_params: true)

  • Merges context into component context with priority

  • Wraps returned context under namespace key

  • Prefixes error paths with namespace

Examples:

Nested author creation

# params: { title: 'Hello', author: { name: 'John', email: '[email protected]' } }
namespace(:author, create_author)
# Inner receives: { name: 'John', email: '[email protected]' }
# Result context: { author: { author: <Author> } }
# Error paths: [:author, :email] instead of [:email]

Shared params for multiple processors

parallel(
  namespace(:cache, warm_cache, shared_params: true),
  namespace(:search, index_search, shared_params: true)
)
# Both receive full params; results namespaced separately

Sequential namespace accumulation

sequence(
  namespace(:author, validate_author),  # => { author: { validated: true } }
  namespace(:author, create_author)     # => { author: { validated: true, author: <Author> } }
)

Instance Method Summary collapse

Methods included from Strict

#call!

Instance Method Details

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



44
45
46
47
48
49
50
# File 'lib/omni_service/namespace.rb', line 44

def call(*params, **context)
  inner_params = prepare_params(params)
  inner_context = prepare_context(context)
  inner_result = component_wrapper.call(*inner_params, **inner_context)

  transform_result(inner_result, params:, context:, inner_context_keys: inner_context.keys)
end