aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-25 08:48:30 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-25 08:48:30 +0000
commit7f86e026f6411d3a557831efbb1af121e791eb31 (patch)
treeeef44d9a1b4c2a9f8f28b2af5be1c4f553f3fd3d /activerecord
parent948be2c998c9e3e56da742b38bc0ab57b75c8d2d (diff)
downloadrails-7f86e026f6411d3a557831efbb1af121e791eb31.tar.gz
rails-7f86e026f6411d3a557831efbb1af121e791eb31.tar.bz2
rails-7f86e026f6411d3a557831efbb1af121e791eb31.zip
Use assignment instead of call
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2327 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG8
-rw-r--r--activerecord/lib/active_record/observer.rb11
-rwxr-xr-xactiverecord/test/lifecycle_test.rb12
3 files changed, 13 insertions, 18 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 393bca06a1..291b0649e1 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,12 +1,8 @@
*SVN*
-* Added new symbol-driven approach to activating observers with Base#observer [DHH]. Example:
+* Added new symbol-driven approach to activating observers with Base#observers= [DHH]. Example:
- ActiveRecord::Base.observer(:cacher, :garbage_collector)
-
- ...which is the same as doing:
-
- [ Cacher.instance, GarbageCollector.instance ]
+ ActiveRecord::Base.observers = :cacher, :garbage_collector
* Added AbstractAdapter#select_value and AbstractAdapter#select_values as convenience methods for selecting single values, instead of hashes, of the first column in a SELECT #2283 [solo@gatelys.com]
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb
index 36fcf021cd..1a167667e3 100644
--- a/activerecord/lib/active_record/observer.rb
+++ b/activerecord/lib/active_record/observer.rb
@@ -10,16 +10,15 @@ module ActiveRecord
module ClassMethods
# Activates the observers assigned. Examples:
#
- # # Calls PersonObserver.instance and returns the instance of that observer
- # ActiveRecord::Base.observer(:person_observer)
+ # # Calls PersonObserver.instance
+ # ActiveRecord::Base.observers = :person_observer
#
# # Calls Cacher.instance and GarbageCollector.instance
- # # and returns an array with instances of both
- # ActiveRecord::Base.observer(:cacher, :garbage_collector)
+ # ActiveRecord::Base.observers = :cacher, :garbage_collector
#
# # Same as above, just using explicit class references
- # ActiveRecord::Base.observer(Cacher, GarbageCollector)
- def observer(*observers)
+ # ActiveRecord::Base.observers = Cacher, GarbageCollector
+ def observers=(*observers)
observers = [ observers ].flatten.collect do |observer|
observer.is_a?(Symbol) ?
observer.to_s.camelize.constantize.instance :
diff --git a/activerecord/test/lifecycle_test.rb b/activerecord/test/lifecycle_test.rb
index a373471f19..ddac6f7c4c 100755
--- a/activerecord/test/lifecycle_test.rb
+++ b/activerecord/test/lifecycle_test.rb
@@ -65,22 +65,22 @@ class LifecycleTest < Test::Unit::TestCase
end
def test_after_save
- topic_observer = ActiveRecord::Base.observer(:topic_manual_observer)
+ ActiveRecord::Base.observers = :topic_manual_observer
topic = Topic.find(1)
topic.title = "hello"
topic.save
- assert topic_observer.has_been_notified?
- assert_equal :after_save, topic_observer.callbacks.last["callback_method"]
+ assert TopicManualObserver.instance.has_been_notified?
+ assert_equal :after_save, TopicManualObserver.instance.callbacks.last["callback_method"]
end
def test_observer_update_on_save
- topic_observer = ActiveRecord::Base.observer(TopicManualObserver)
+ ActiveRecord::Base.observers = TopicManualObserver
topic = Topic.find(1)
- assert topic_observer.has_been_notified?
- assert_equal :after_find, topic_observer.callbacks.first["callback_method"]
+ assert TopicManualObserver.instance.has_been_notified?
+ assert_equal :after_find, TopicManualObserver.instance.callbacks.first["callback_method"]
end
def test_auto_observer