aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/paths.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-03-26 17:25:44 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-03-26 17:25:44 -0700
commit494610792530bc21f5c284a4eb66278b07953a5b (patch)
tree59ac0f334b85eec06fd93d781b40ab7325f3d8d9 /railties/lib/rails/paths.rb
parent41dfc46717754c48c6957b6495c35b812109a8b7 (diff)
downloadrails-494610792530bc21f5c284a4eb66278b07953a5b.tar.gz
rails-494610792530bc21f5c284a4eb66278b07953a5b.tar.bz2
rails-494610792530bc21f5c284a4eb66278b07953a5b.zip
favor composition over inheritance
Diffstat (limited to 'railties/lib/rails/paths.rb')
-rw-r--r--railties/lib/rails/paths.rb36
1 files changed, 29 insertions, 7 deletions
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb
index d9c47c0498..82c40ebe4b 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -16,13 +16,13 @@ module Rails
# path.eager_load? # => true
# path.is_a?(Rails::Paths::Path) # => true
#
- # The +Path+ object is simply an array and allows you to easily add extra paths:
+ # The +Path+ object is simply an enumerable and allows you to easily add extra paths:
#
- # path.is_a?(Array) # => true
- # path.inspect # => ["app/controllers"]
+ # path.is_a?(Enumerable) # => true
+ # path.to_ary.inspect # => ["app/controllers"]
#
# path << "lib/controllers"
- # path.inspect # => ["app/controllers", "lib/controllers"]
+ # path.to_ary.inspect # => ["app/controllers", "lib/controllers"]
#
# Notice that when you add a path using +add+, the path object created already
# contains the path with the same path value given to +add+. In some situations,
@@ -100,13 +100,14 @@ module Rails
end
end
- class Path < Array
+ class Path
+ include Enumerable
+
attr_reader :path
attr_accessor :glob
def initialize(root, current, paths, options = {})
- super(paths)
-
+ @paths = paths
@current = current
@root = root
@glob = options[:glob]
@@ -147,6 +148,27 @@ module Rails
RUBY
end
+ def each(&block)
+ @paths.each &block
+ end
+
+ def <<(path)
+ @paths << path
+ end
+ alias :push :<<
+
+ def concat(paths)
+ @paths.concat paths
+ end
+
+ def unshift(path)
+ @paths.unshift path
+ end
+
+ def to_ary
+ @paths
+ end
+
# Expands all paths against the root and return all unique values.
def expanded
raise "You need to set a path root" unless @root.path