Class: ActiveRecord::Observer

Inherits:
Object
  • Object
show all
Defined in:
lib/extended_observers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.observe(*models) ⇒ Object

Attaches the observer to the supplied model classes.



13
14
15
16
17
18
19
# File 'lib/extended_observers.rb', line 13

def observe(*models)
  options = models.extract_options!
  set_watch_options(models, options)
  models = constantize_models(models)
  already_observed = read_inheritable_attribute(:observed_classes)
  write_inheritable_attribute(:observed_classes, Set.new(Array(already_observed)) + Set.new(models))
end

Instance Method Details

#observed_classesObject



49
50
51
# File 'lib/extended_observers.rb', line 49

def observed_classes
  self.class.read_inheritable_attribute(:observed_classes) || Set.new([self.class.observed_class].compact.flatten)
end

#update(observed_method, object) ⇒ Object

Send observed_method(object) if the method exists.



45
46
47
# File 'lib/extended_observers.rb', line 45

def update(observed_method, object) #:nodoc:
  send(observed_method, object) if listening_for?(object, observed_method)
end