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



21
22
23
24
25
# File 'lib/active_admin/event.rb', line 21

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

#subscribe(event, &block) ⇒ Object



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

def subscribe(event, &block)
  @events[event] ||= []
  @events[event] << block
end

#subscribers(event) ⇒ Object



17
18
19
# File 'lib/active_admin/event.rb', line 17

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