Module: Trailblazer::V1_1::Operation::Callback

Defined in:
lib/trailblazer/1.1/operation/callback.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


5
6
7
8
9
10
# File 'lib/trailblazer/1.1/operation/callback.rb', line 5

def self.included(base)
  base.extend ClassMethods

  base.extend Declarative::Heritage::Inherited
  base.extend Declarative::Heritage::DSL
end

Instance Method Details

#callback!(name = :default, options = { operation: self, contract: contract, params: @params }) ⇒ Object

FIXME: test options.


12
13
14
15
16
17
18
19
20
# File 'lib/trailblazer/1.1/operation/callback.rb', line 12

def callback!(name=:default, options={ operation: self, contract: contract, params: @params }) # FIXME: test options.
  config  = self.class.callbacks.fetch(name) # TODO: test exception
  group   = config[:group].new(contract)

  options[:context] ||= (config[:context] == :operation ? self : group)
  group.(options)

  invocations[name] = group
end

#dispatch!(*args, &block) ⇒ Object


22
23
24
# File 'lib/trailblazer/1.1/operation/callback.rb', line 22

def dispatch!(*args, &block)
  callback!(*args, &block)
end

#invocationsObject


26
27
28
# File 'lib/trailblazer/1.1/operation/callback.rb', line 26

def invocations
  @invocations ||= {}
end