Permalink
Browse files

Refactor ActiveRecord::Base.reset_subclasses to #reset, and add globa…

…l observer resetting. [Rick Olson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4683 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent a7f1586 commit e8f0b1ddd97cfcefc32554a1a9447ec092c4d0ae @technoweenie technoweenie committed Aug 6, 2006
Showing with 22 additions and 2 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +4 −0 activerecord/lib/active_record/base.rb
  3. +16 −2 activerecord/lib/active_record/observer.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Refactor ActiveRecord::Base.reset_subclasses to #reset, and add global observer resetting. [Rick Olson]
+
* Formally deprecate the deprecated finders. [Koz]
* Formally deprecate rich associations. [Koz]
@@ -272,6 +272,10 @@ def self.inherited(child) #:nodoc:
super
end
+ def self.reset
+ reset_subclasses
+ end
+
def self.reset_subclasses #:nodoc:
nonreloadables = []
subclasses.each do |klass|
@@ -4,10 +4,18 @@
module ActiveRecord
module Observing # :nodoc:
def self.included(base)
- base.extend(ClassMethods)
+ class << base
+ include ClassMethods
+ alias_method_chain :reset, :observers
+ end
end
module ClassMethods
+ def reset_with_observers # :nodoc:
+ reset_without_observers
+ instantiate_observers
+ end
+
# Activates the observers assigned. Examples:
#
# # Calls PersonObserver.instance
@@ -19,7 +27,13 @@ module ClassMethods
# # Same as above, just using explicit class references
# ActiveRecord::Base.observers = Cacher, GarbageCollector
def observers=(*observers)
- observers.flatten.each do |observer|
+ @observers = observers.flatten
+ end
+
+ # Instantiate the global ActiveRecord observers
+ def instantiate_observers
+ return if @observers.blank?
+ @observers.each do |observer|
if observer.respond_to?(:to_sym) # Symbol or String
observer.to_s.camelize.constantize.instance
elsif observer.respond_to?(:instance)

0 comments on commit e8f0b1d

Please sign in to comment.