Module: Trailblazer::Operation::Callback::DSL

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

Instance Method Summary collapse

Instance Method Details

#callback(name = :default, constant = nil, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/trailblazer/operation/callback.rb', line 22

def callback(name=:default, constant=nil, &block)
  heritage.record(:callback, name, constant, &block)

  # FIXME: make this nicer. we want to extend same-named callback groups.
  # TODO: allow the same with contract, or better, test it!
  extended = self["callback.#{name}.class"] && self["callback.#{name}.class"]

  path, group_class = Trailblazer::DSL::Build.new.({ prefix: :callback, class: Disposable::Callback::Group, container: self }, name, constant, block) { |extended| extended[:group] }

  self[path] = { group: group_class, context: constant ? nil : :operation }
end