module Shout::ClassMethods

Attributes

events_notified[RW]
events_notified_misspellings[RW]
observer_class_names[RW]

Internal Methods

observer_class_names_check[RW]

Public Class Methods

extended(mod) click to toggle source
# File lib/shout/observable.rb, line 59
def self.extended(mod)
  mod.observer_class_names = []
  mod.observer_class_names_check = []
  mod.events_notified = []
  mod.events_notified_misspellings = {}
end

Public Instance Methods

check_observer_classes() click to toggle source
# File lib/shout/observable.rb, line 65
def check_observer_classes
  return if @checked
  here_not_there = (observer_class_names - observer_class_names_check)
  there_not_here = (observer_class_names_check - observer_class_names)
  unless here_not_there == there_not_here
    missing = (here_not_there + there_not_here)

    meths = "#{self}.shout_observers(#{missing.map(&:inspect)}) and "+
      missing.map{|observer|
        "#{observer}.observes=#{self.name.to_sym.inspect}"
      }.join(' and ')
    
    raise ArgumentError.new("#{self}: Please call both #{meths} to observe #{self}. This is done to ensure determinism in the load order in development, test, and production environments.")
  end
  @checked = true
end
load_observers(instance) click to toggle source
# File lib/shout/observable.rb, line 81
def load_observers(instance)
  check_observer_classes
  self.observer_class_names.map{|name|
    k = Shout.constantize(name.to_s)
    instance.idemp_observer(k,k.new(instance))
  }
end
shout_events(event_names) click to toggle source

Implementor Methods

# File lib/shout/observable.rb, line 44
def shout_events(event_names)
  self.events_notified += event_names.map(&:to_sym)
end
shout_misspellings(event_misspellings) click to toggle source
# File lib/shout/observable.rb, line 47
def shout_misspellings(event_misspellings)
  self.events_notified_misspellings.merge!(event_misspellings)
end
shout_observers(listener_classes) click to toggle source
# File lib/shout/observable.rb, line 50
def shout_observers(listener_classes)
  self.observer_class_names += listener_classes
end