aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/observer.rb8
2 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 5d437a3e70..e62d77a60d 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add an attribute reader method for ActiveRecord::Base.observers [Rick Olson]
+
* Deprecation: count class method should be called with an options hash rather than two args for conditions and joins. #6287 [Bob Silva]
* has_one associations with a nil target may be safely marshaled. #6279 [norbauer, Jeremy Kemper]
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb
index b472423b88..ace52ef415 100644
--- a/activerecord/lib/active_record/observer.rb
+++ b/activerecord/lib/active_record/observer.rb
@@ -18,10 +18,18 @@ module ActiveRecord
#
# # Same as above, just using explicit class references
# ActiveRecord::Base.observers = Cacher, GarbageCollector
+ #
+ # Note: Setting this does not instantiate the observers yet. #instantiate_observers is
+ # called during startup, and before each development request.
def observers=(*observers)
@observers = observers.flatten
end
+ # Gets the current observers.
+ def observers
+ @observers ||= []
+ end
+
# Instantiate the global ActiveRecord observers
def instantiate_observers
return if @observers.blank?