Sha256: fd4ec876ee63011ed2400fe8c304e2b72f379a6c3b73b436ad2c5adfe8eb0f54

Contents?: true

Size: 582 Bytes

Versions: 90

Compression:

Stored size: 582 Bytes

Contents

module ActiveAdmin

  class EventDispatcher
    def initialize
      @events = {}
    end

    def clear_all_subscribers!
      @events = {}
    end

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

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

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

  # ActiveAdmin::Event is set to a dispatcher
  Event = EventDispatcher.new

end

Version data entries

90 entries across 90 versions & 7 rubygems

Version Path
activeadmin-0.5.0.pre lib/active_admin/event.rb
activeadmin-0.4.4 lib/active_admin/event.rb
activeadmin-0.4.3 lib/active_admin/event.rb
activeadmin-0.4.2 lib/active_admin/event.rb
activeadmin-0.4.1 lib/active_admin/event.rb
activeadmin-0.4.0 lib/active_admin/event.rb
andrewroth_activeadmin-0.3.4.4 lib/active_admin/event.rb
andrewroth_activeadmin-0.3.4.3 lib/active_admin/event.rb
andrewroth_activeadmin-0.3.4.2 lib/active_admin/event.rb
andrewroth_activeadmin-0.3.4.1 lib/active_admin/event.rb