Module: Protocolist::ControllerAdditions::ClassMethods

Defined in:
lib/protocolist/controller_additions.rb

Instance Method Summary collapse

Instance Method Details

#fires(activity_type, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/protocolist/controller_additions.rb', line 27

def fires(activity_type, options = {})
  options = options.merge(only: activity_type) unless options[:only] || options[:except]

  data_proc = extract_data_proc(options[:data])

  options_for_callback = options.slice(:if, :unless, :only, :except)
  options_for_fire     = options.except(:if, :unless, :only, :except)

  callback_proc = ->(controller; options) do
    options = options_for_fire.merge(data: data_proc.call(controller))

    controller.fire(activity_type, options)
  end

  send(:after_filter, callback_proc, options_for_callback)
end