Class: ActiveAdmin::EventDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/event.rb

Instance Method Summary collapse

Constructor Details

#initializeEventDispatcher

Returns a new instance of EventDispatcher.



4
5
6
# File 'lib/active_admin/event.rb', line 4

def initialize
  @events = {}
end

Instance Method Details

#clear_all_subscribers!Object



8
9
10
# File 'lib/active_admin/event.rb', line 8

def clear_all_subscribers!
  @events = {}
end

#dispatch(event, *args) ⇒ Object



23
24
25
26
27
# File 'lib/active_admin/event.rb', line 23

def dispatch(event, *args)
  subscribers(event).each do |subscriber|
    subscriber.call(*args)
  end
end

#subscribe(*event_names, &block) ⇒ Object



12
13
14
15
16
17
# File 'lib/active_admin/event.rb', line 12

def subscribe(*event_names, &block)
  event_names.each do |event|
    @events[event] ||= []
    @events[event] << block
  end
end

#subscribers(event) ⇒ Object



19
20
21
# File 'lib/active_admin/event.rb', line 19

def subscribers(event)
  @events[event] || []
end