module Skr::Concerns::PubSub::ClassMethods
Public Instance Methods
_add_event_listener( name, proc )
click to toggle source
# File lib/skr/concerns/pub_sub.rb, line 56 def _add_event_listener( name, proc ) self.event_listeners[name].push( proc ) unless self.event_listeners[name].include?(proc) end
_ensure_validate_event(event)
click to toggle source
# File lib/skr/concerns/pub_sub.rb, line 65 def _ensure_validate_event(event) unless self.valid_event_names.include?(event.to_sym) raise InvalidEvent.new("#{event} is not a valid event for #{self}") end end
event_listeners()
click to toggle source
# File lib/skr/concerns/pub_sub.rb, line 52 def event_listeners self._event_listeners ||= Hash.new{ |hash, key| hash[key]=Array.new } end
inherited(base)
click to toggle source
Calls superclass method
# File lib/skr/concerns/pub_sub.rb, line 43 def inherited(base) super klass = base.to_s.demodulize if PendingEventListeners.all.has_key?( klass ) events = PendingEventListeners.all.delete(klass) events.each{ | name, procs | base.event_listeners[name] += procs } end end
observe( event, &block )
click to toggle source
# File lib/skr/concerns/pub_sub.rb, line 60 def observe( event, &block ) _ensure_validate_event( event ) _add_event_listener( event.to_sym, block ) end
Protected Instance Methods
has_additional_events( *names )
click to toggle source
# File lib/skr/concerns/pub_sub.rb, line 73 def has_additional_events( *names ) self.valid_event_names += names.map{ |name| name.to_sym } end