aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2012-04-29 16:30:54 -0400
committerMarc-Andre Lafortune <github@marc-andre.ca>2012-04-30 18:10:03 -0400
commit24c068d67dab4559ab24f77482cd671563161ec2 (patch)
treee6ab5b9bcc46cb28a2d103deff50a08526df7eed /activemodel/lib/active_model
parentad2c5ea2786817592014fae09934398173c1a7f9 (diff)
downloadrails-24c068d67dab4559ab24f77482cd671563161ec2.tar.gz
rails-24c068d67dab4559ab24f77482cd671563161ec2.tar.bz2
rails-24c068d67dab4559ab24f77482cd671563161ec2.zip
Allow extra arguments for Observers
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/observing.rb26
1 files changed, 17 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb
index 35b1a1f0c7..99b32300ca 100644
--- a/activemodel/lib/active_model/observing.rb
+++ b/activemodel/lib/active_model/observing.rb
@@ -112,13 +112,21 @@ module ActiveModel
private
# Fires notifications to model's observers
#
- # def save
- # notify_observers(:before_save)
- # ...
- # notify_observers(:after_save)
- # end
- def notify_observers(method)
- self.class.notify_observers(method, self)
+ # def save
+ # notify_observers(:before_save)
+ # ...
+ # notify_observers(:after_save)
+ # end
+ #
+ # Custom notifications can be sent in a similar fashion:
+ #
+ # notify_observers(:custom_notification, :foo)
+ #
+ # This will call +custom_notification+, passing as arguments
+ # the current object and :foo.
+ #
+ def notify_observers(method, *extra_args)
+ self.class.notify_observers(method, self, *extra_args)
end
end
@@ -229,10 +237,10 @@ module ActiveModel
# Send observed_method(object) if the method exists and
# the observer is enabled for the given object's class.
- def update(observed_method, object, &block) #:nodoc:
+ def update(observed_method, object, *extra_args, &block) #:nodoc:
return unless respond_to?(observed_method)
return if disabled_for?(object)
- send(observed_method, object, &block)
+ send(observed_method, object, *extra_args, &block)
end
# Special method sent by the observed class when it is inherited.