diff options
author | Mislav Marohnić <mislav.marohnic@gmail.com> | 2010-04-16 19:30:40 +0200 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-04-16 13:09:07 -0700 |
commit | c2ca73c9ee5fc3dadf69cf565bd5e2bb30c82c50 (patch) | |
tree | 24295cda52cb05dc1c8914c677366fdb823df909 /activemodel | |
parent | cf616e48765d1aa378d04618c044b493fd9583e1 (diff) | |
download | rails-c2ca73c9ee5fc3dadf69cf565bd5e2bb30c82c50.tar.gz rails-c2ca73c9ee5fc3dadf69cf565bd5e2bb30c82c50.tar.bz2 rails-c2ca73c9ee5fc3dadf69cf565bd5e2bb30c82c50.zip |
ActiveModel::Observing: stop using Observable Ruby module, re-implement `notify_observers`
`Observable#notify_observers` from Ruby always returns false (which halts ActiveRecord
callback chains) and has extra features (like `changed`) that were never used.
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/observing.rb | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb index ed6fb47c7e..f9ee142bfd 100644 --- a/activemodel/lib/active_model/observing.rb +++ b/activemodel/lib/active_model/observing.rb @@ -1,4 +1,3 @@ -require 'observer' require 'singleton' require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/module/aliasing' @@ -8,10 +7,6 @@ module ActiveModel module Observing extend ActiveSupport::Concern - included do - extend Observable - end - module ClassMethods # Activates the observers assigned. Examples: # @@ -41,6 +36,22 @@ module ActiveModel observers.each { |o| instantiate_observer(o) } end + def add_observer(observer) + unless observer.respond_to? :update + raise ArgumentError, "observer needs to respond to `update'" + end + @observer_instances ||= [] + @observer_instances << observer + end + + def notify_observers(*arg) + if defined? @observer_instances + for observer in @observer_instances + observer.update(*arg) + end + end + end + protected def instantiate_observer(observer) #:nodoc: # string/symbol @@ -56,7 +67,6 @@ module ActiveModel # Notify observers when the observed class is subclassed. def inherited(subclass) super - changed notify_observers :observed_class_inherited, subclass end end @@ -70,7 +80,6 @@ module ActiveModel # notify_observers(:after_save) # end def notify_observers(method) - self.class.changed self.class.notify_observers(method, self) end end |