aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-11-30 10:14:01 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-11-30 10:17:27 -0800
commit5b3d4f07857e2f86ea8df702ba7c42e144b54970 (patch)
treed3df99672d13c64330be5c041880c5b673ab7a51
parent88daf082581bcec5fcdbb92d1fd784188e4d99bd (diff)
downloadrails-5b3d4f07857e2f86ea8df702ba7c42e144b54970.tar.gz
rails-5b3d4f07857e2f86ea8df702ba7c42e144b54970.tar.bz2
rails-5b3d4f07857e2f86ea8df702ba7c42e144b54970.zip
switch WatchStack to use composition, tighten up API
-rw-r--r--activesupport/lib/active_support/dependencies.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 1372e71a61..100b48312a 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -71,14 +71,20 @@ module ActiveSupport #:nodoc:
#
# This is handled by walking back up the watch stack and adding the constants
# found by child.rb to the list of original constants in parent.rb
- class WatchStack < Hash
+ class WatchStack
+ include Enumerable
+
# @watching is a stack of lists of constants being watched. For instance,
# if parent.rb is autoloaded, the stack will look like [[Object]]. If parent.rb
# then requires namespace/child.rb, the stack will look like [[Object], [Namespace]].
def initialize
@watching = []
- super { |h,k| h[k] = [] }
+ @stack = Hash.new { |h,k| h[k] = [] }
+ end
+
+ def each(&block)
+ @stack.each(&block)
end
# return a list of new constants found since the last call to watch_namespaces
@@ -89,7 +95,7 @@ module ActiveSupport #:nodoc:
@watching.last.each do |namespace|
# Retrieve the constants that were present under the namespace when watch_namespaces
# was originally called
- original_constants = self[namespace].last
+ original_constants = @stack[namespace].last
mod = Inflector.constantize(namespace) if Dependencies.qualified_const_defined?(namespace)
next unless mod.is_a?(Module)
@@ -102,7 +108,7 @@ module ActiveSupport #:nodoc:
# element of self[Object] will be an Array of the constants that were present
# before parent.rb was required. The second element will be an Array of the
# constants that were present before child.rb was required.
- self[namespace].each do |namespace_constants|
+ @stack[namespace].each do |namespace_constants|
namespace_constants.concat(new_constants)
end
@@ -126,13 +132,14 @@ module ActiveSupport #:nodoc:
Inflector.constantize(module_name).local_constant_names : []
watching << module_name
- self[module_name] << original_constants
+ @stack[module_name] << original_constants
end
@watching << watching
end
+ private
def pop_modules(modules)
- modules.each { |mod| self[mod].pop }
+ modules.each { |mod| @stack[mod].pop }
end
end