aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-05-10 10:56:09 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-05-10 10:56:09 -0700
commit3aee9126aa6309538ee64064dcabcd34d7cc7d26 (patch)
tree5c101f2689a2dbeb98ac5f7ad8552eb6614bd4e6 /activesupport/lib/active_support
parent5bc4740dec7ec9846915f7af459056d486b9c89d (diff)
downloadrails-3aee9126aa6309538ee64064dcabcd34d7cc7d26.tar.gz
rails-3aee9126aa6309538ee64064dcabcd34d7cc7d26.tar.bz2
rails-3aee9126aa6309538ee64064dcabcd34d7cc7d26.zip
use delegation over inheritance so we can figure when to cache / bust cache
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/callbacks.rb27
1 files changed, 22 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 7c71524ffe..13dccf328c 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -338,7 +338,9 @@ module ActiveSupport
end
# An Array with a compile method.
- class CallbackChain < Array #:nodoc:#
+ class CallbackChain #:nodoc:#
+ include Enumerable
+
attr_reader :name, :config
def initialize(name, config)
@@ -347,6 +349,18 @@ module ActiveSupport
:terminator => "false",
:scope => [ :kind ]
}.merge!(config)
+ @chain = []
+ end
+
+ def each(&block); @chain.each(&block); end
+ def index(o); @chain.index(o); end
+ def insert(index, o); @chain.insert(index, o); end
+ def delete(o); @chain.delete(o); end
+ def clear; @chain.clear; self; end
+ def empty?; @chain.empty?; end
+
+ def initialize_copy(other)
+ @chain = other.chain.dup
end
def compile
@@ -355,7 +369,7 @@ module ActiveSupport
env.value = !env.halted && (!block || block.call)
env
}
- reverse_each do |callback|
+ @chain.reverse_each do |callback|
callbacks = callback.apply(callbacks)
end
callbacks
@@ -369,20 +383,23 @@ module ActiveSupport
callbacks.each { |c| prepend_one(c) }
end
+ protected
+ def chain; @chain; end
+
private
def append_one(callback)
remove_duplicates(callback)
- push(callback)
+ @chain.push(callback)
end
def prepend_one(callback)
remove_duplicates(callback)
- unshift(callback)
+ @chain.unshift(callback)
end
def remove_duplicates(callback)
- delete_if { |c| callback.duplicates?(c) }
+ @chain.delete_if { |c| callback.duplicates?(c) }
end
end