Skip to content
Browse files

use delegation over inheritance so we can figure when to cache / bust…

… cache
  • Loading branch information...
1 parent 5bc4740 commit 3aee9126aa6309538ee64064dcabcd34d7cc7d26 @tenderlove tenderlove committed May 10, 2013
Showing with 22 additions and 5 deletions.
  1. +22 −5 activesupport/lib/active_support/callbacks.rb
View
27 activesupport/lib/active_support/callbacks.rb
@@ -338,7 +338,9 @@ def filter.around(context)
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 @@ def initialize(name, config)
: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 @@ def compile
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 @@ def prepend(*callbacks)
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

0 comments on commit 3aee912

Please sign in to comment.
Something went wrong with that request. Please try again.