diff options
author | Myron Marston <myron.marston@gmail.com> | 2011-04-28 08:27:15 -0700 |
---|---|---|
committer | Myron Marston <myron.marston@gmail.com> | 2011-04-28 08:27:15 -0700 |
commit | fef22157b07f101229d29544d578bfe2cb9fedfe (patch) | |
tree | 8053e5b9495da805f4eb12c34885583346914a5e /activemodel/lib/active_model/observing.rb | |
parent | 9a385394acd6599ff588daad491e9e07ee716091 (diff) | |
download | rails-fef22157b07f101229d29544d578bfe2cb9fedfe.tar.gz rails-fef22157b07f101229d29544d578bfe2cb9fedfe.tar.bz2 rails-fef22157b07f101229d29544d578bfe2cb9fedfe.zip |
Fix bug with AM::Observer disablement.
Now that we propagate the enabling/disabling to descendants, we no longer have to check the disabled_observer Set on each superclass of the model class. This was causing a bug when disabling all observers at a superclass level and then enabling an individual observer at a subclass level.
Plus the logic is simpler now :).
Diffstat (limited to 'activemodel/lib/active_model/observing.rb')
-rw-r--r-- | activemodel/lib/active_model/observing.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb index 9ffcda8dd7..c1ac4eb4af 100644 --- a/activemodel/lib/active_model/observing.rb +++ b/activemodel/lib/active_model/observing.rb @@ -222,9 +222,9 @@ module ActiveModel # Send observed_method(object) if the method exists. def update(observed_method, object) #:nodoc: - if respond_to?(observed_method) && ObserverArray.observer_enabled?(self, object) - send(observed_method, object) - end + return unless respond_to?(observed_method) + return if disabled_for?(object) + send(observed_method, object) end # Special method sent by the observed class when it is inherited. @@ -238,5 +238,11 @@ module ActiveModel def add_observer!(klass) #:nodoc: klass.add_observer(self) end + + def disabled_for?(object) + klass = object.class + return false unless klass.respond_to?(:observers) + klass.observers.disabled_for?(self) + end end end |