diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-04-17 23:30:01 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-04-17 23:30:01 -0500 |
commit | cf04e621270bb2e5e9e7971d2c59e73d6797482d (patch) | |
tree | af14a01cb712d6ade17f39da3a8103d7bf3bfd8c /activesupport/lib/active_support | |
parent | 82b4faf81218bbd8916ab559590db236c7f80e46 (diff) | |
download | rails-cf04e621270bb2e5e9e7971d2c59e73d6797482d.tar.gz rails-cf04e621270bb2e5e9e7971d2c59e73d6797482d.tar.bz2 rails-cf04e621270bb2e5e9e7971d2c59e73d6797482d.zip |
Tidy up ActiveSupport::Callbacks::CallbackChain instance API.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 329cc2fdc7..282b6cbcbc 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -96,17 +96,26 @@ module ActiveSupport end end - def find_callback(callback, &block) + def |(chain) + if chain.is_a?(Callback) + if found_callback = find(chain) + index = index(found_callback) + self[index] = chain + else + self << chain + end + else + chain.each { |callback| self | callback } + end + self + end + + def find(callback, &block) select { |c| c == callback && (!block_given? || yield(c)) }.first end - def replace_or_append_callback(callback) - if found_callback = find_callback(callback) - index = index(found_callback) - self[index] = callback - else - self << callback - end + def delete(callback) + super(find(callback)) end private |