Class: Operations::Components::Operation

Inherits:
Base
  • Object
show all
Defined in:
lib/operations/components/operation.rb

Overview

Wraps operation component call to adapt to the further processing.

Constant Summary collapse

PARAMS_FIRST_SIGNATURES =
[[:params], [:_params], [:_]].freeze

Constants inherited from Base

Base::DEFAULT_NAMES_MAP, Base::MONADS_DO_WRAPPER_SIGNATURES

Instance Method Summary collapse

Instance Method Details

#call(params, context) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/operations/components/operation.rb', line 9

def call(params, context)
  arg_names = call_args(callable, types: %i[req opt])

  operation_result = if PARAMS_FIRST_SIGNATURES.include?(arg_names)
    callable.call(params, **context)
  else
    context_args = context.values_at(*arg_names)
    callable.call(*context_args, **params)
  end

  extended_result(operation_result, params: params, context: context)
end