module Hippo::Concerns::PubSub::ClassMethods

Public Instance Methods

inherited(base) click to toggle source
Calls superclass method
# File lib/hippo/concerns/pub_sub.rb, line 60
def inherited(base)
    super
    klass = base.to_s.demodulize
    events = PubSub::PendingListeners.claim( klass )
    events.each{ | name, procs |
        procs.each{|pr|
            base.send(:_add_event_listener, name, &pr)
        }
    }
end
observe( event, &block ) click to toggle source
# File lib/hippo/concerns/pub_sub.rb, line 71
def observe( event, &block )
    unless self.valid_event_names.include?(event.to_sym)
        raise InvalidEvent.new("#{event} is not a valid event for #{self}")
    end
    _add_event_listener( event.to_sym, &block )
end

Protected Instance Methods

has_additional_events( *names ) click to toggle source
# File lib/hippo/concerns/pub_sub.rb, line 80
def has_additional_events( *names )
    self.valid_event_names += names.map{ |name| name.to_sym }
end

Private Instance Methods

_add_event_listener(name, &block) click to toggle source
# File lib/hippo/concerns/pub_sub.rb, line 86
def _add_event_listener(name, &block)
    self._event_listeners ||= Hash.new{ |hash, key| hash[key]=Array.new }
    listeners = self._event_listeners[name].dup
    listeners << block
    self._event_listeners = self._event_listeners.dup
    self._event_listeners[name] = listeners
end