aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-04-20 11:45:44 -0500
committerJoshua Peek <josh@joshpeek.com>2008-04-20 11:45:44 -0500
commit46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd (patch)
treeb8b28b08ced54f68137f43d796db00ffd8205b89 /activesupport/lib
parent14a40804a29a57ad05ca6bffbe1e5334089593a9 (diff)
downloadrails-46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd.tar.gz
rails-46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd.tar.bz2
rails-46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd.zip
Use define_callbacks helper for ActiveRecord validations.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/callbacks.rb20
1 files changed, 10 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 5c51237049..9c59b7ac76 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -99,8 +99,8 @@ module ActiveSupport
def |(chain)
if chain.is_a?(CallbackChain)
chain.each { |callback| self | callback }
- elsif chain.is_a?(Callback)
- if index = index(chain)
+ else
+ if (found_callback = find(chain)) && (index = index(chain))
self[index] = chain
else
self << chain
@@ -224,8 +224,8 @@ module ActiveSupport
end
end
- # Runs all the callbacks defined for the given options.
- #
+ # Runs all the callbacks defined for the given options.
+ #
# If a block is given it will be called after each callback receiving as arguments:
#
# * the result from the callback
@@ -236,31 +236,31 @@ module ActiveSupport
# Example:
# class Storage
# include ActiveSupport::Callbacks
- #
+ #
# define_callbacks :before_save, :after_save
# end
- #
+ #
# class ConfigStorage < Storage
# before_save :pass
# before_save :pass
# before_save :stop
# before_save :pass
- #
+ #
# def pass
# puts "pass"
# end
- #
+ #
# def stop
# puts "stop"
# return false
# end
- #
+ #
# def save
# result = run_callbacks(:before_save) { |result, object| result == false }
# puts "- save" if result
# end
# end
- #
+ #
# config = ConfigStorage.new
# config.save
#