diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2010-04-25 17:07:55 +1000 |
---|---|---|
committer | Mikel Lindsaar <raasdnil@gmail.com> | 2010-04-25 17:07:55 +1000 |
commit | e1b255aca456a5b456111b09237805fd32d15111 (patch) | |
tree | a87c8b8989449a9dbdf1c6897901f6957ec021dc /activemodel/lib/active_model/observing.rb | |
parent | 60ab54113fa833a1258d687673561b9474964149 (diff) | |
parent | a5955196f2ed8a69c49a1a8c0c617ab91cb8d716 (diff) | |
download | rails-e1b255aca456a5b456111b09237805fd32d15111.tar.gz rails-e1b255aca456a5b456111b09237805fd32d15111.tar.bz2 rails-e1b255aca456a5b456111b09237805fd32d15111.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activemodel/lib/active_model/observing.rb')
-rw-r--r-- | activemodel/lib/active_model/observing.rb | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb index ed6fb47c7e..74a33d45ab 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,26 @@ 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 + + def count_observers + @observer_instances.size + end + protected def instantiate_observer(observer) #:nodoc: # string/symbol @@ -56,7 +71,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 +84,6 @@ module ActiveModel # notify_observers(:after_save) # end def notify_observers(method) - self.class.changed self.class.notify_observers(method, self) end end |