module Shout::Listener::ClassMethods
Attributes
callbacks[RW]
observes[R]
Internal Methods
Public Instance Methods
callbacks_for_event(n)
click to toggle source
# File lib/shout/listener.rb, line 65 def callbacks_for_event(n) self.callbacks.select{|name,method| name == n}.map{|name,method| method} end
observes=(observes)
click to toggle source
Sets the class which this observer will observe. A required call.
# File lib/shout/listener.rb, line 25 def observes=(observes) @observes = observes valid_observable? observes_class.observer_class_names_check.push(self.name.to_sym) end
observes_class()
click to toggle source
# File lib/shout/listener.rb, line 44 def observes_class Shout.constantize(self.observes.to_s) rescue NameError => e nil end
shout_callback(name, method)
click to toggle source
Registers a callback which will be executed when the observes_class
's instances call run_callbacks(name).
# File lib/shout/listener.rb, line 32 def shout_callback(name, method) valid_event?(name) callbacks.push([name,method]) end
test_event(name, instance, *params)
click to toggle source
# File lib/shout/listener.rb, line 36 def test_event(name, instance, *params) listener = new(instance) listener.update_with_shout_event(name, *params) end
valid_event?(event)
click to toggle source
# File lib/shout/listener.rb, line 57 def valid_event?(event) if observes_class.events_notified_misspellings.has_key?(event) raise ArgumentError.new("#{self.class}: Well well well, you've found an area of cognitive dissonance! Use #{observes_class.events_notified_misspellings[event].inspect} instead of #{event}.") end unless observes_class.events_notified.include?(event) raise ArgumentError.new("#{self.class}: Oh lordy, this is embarassing. #{event.inspect} is totally not available in #{observes_class}.\nAvailable events:\n#{observes_class.events_notified.inspect}") end end
valid_observable?()
click to toggle source
# File lib/shout/listener.rb, line 49 def valid_observable? unless observes_class raise ArgumentError.new("#{self}.observes = #{observes.inspect}. #{observes.inspect} can't be found as a constant.") end unless observes_class < ::Shout::Observable raise ArgumentError.new("#{self}.observes == #{self.observes} does not inherit from ::Shout::Observable.") end end