class Authie::EventManager

Public Class Methods

new() click to toggle source
# File lib/authie/event_manager.rb, line 5
def initialize
  @callbacks = {}
end

Public Instance Methods

dispatch(event, *args) click to toggle source
# File lib/authie/event_manager.rb, line 9
def dispatch(event, *args)
  callbacks = @callbacks[event.to_sym]
  return if callbacks.nil?

  callbacks.each do |cb|
    cb.call(*args)
  end
end
on(event, &block) click to toggle source
# File lib/authie/event_manager.rb, line 18
def on(event, &block)
  @callbacks[event.to_sym] ||= []
  @callbacks[event.to_sym] << block
end
remove(event, block) click to toggle source
# File lib/authie/event_manager.rb, line 23
def remove(event, block)
  cb = @callbacks[event.to_sym]
  return if cb.nil?

  cb.delete(block)
end