favor composition over inheritance
This commit is contained in:
parent
37c84ed877
commit
bca7770e6c
@ -43,25 +43,40 @@ module Paths
|
|||||||
# root["app/controllers"].existent # => ["/rails/app/controllers"]
|
# root["app/controllers"].existent # => ["/rails/app/controllers"]
|
||||||
#
|
#
|
||||||
# Check the <tt>Rails::Paths::Path</tt> documentation for more information.
|
# Check the <tt>Rails::Paths::Path</tt> documentation for more information.
|
||||||
class Root < ::Hash
|
class Root
|
||||||
attr_accessor :path
|
attr_accessor :path
|
||||||
|
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
raise "Argument should be a String of the physical root path" if path.is_a?(Array)
|
raise "Argument should be a String of the physical root path" if path.is_a?(Array)
|
||||||
@current = nil
|
@current = nil
|
||||||
@path = path
|
@path = path
|
||||||
@root = self
|
@root = {}
|
||||||
super()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def []=(path, value)
|
def []=(path, value)
|
||||||
value = Path.new(self, path, [value].flatten) unless value.is_a?(Path)
|
value = Path.new(self, path, [value].flatten) unless value.is_a?(Path)
|
||||||
super(path, value)
|
@root[path] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(path, options={})
|
def add(path, options={})
|
||||||
with = options[:with] || path
|
with = options[:with] || path
|
||||||
self[path] = Path.new(self, path, [with].flatten, options)
|
@root[path] = Path.new(self, path, [with].flatten, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def [](path)
|
||||||
|
@root[path]
|
||||||
|
end
|
||||||
|
|
||||||
|
def values
|
||||||
|
@root.values
|
||||||
|
end
|
||||||
|
|
||||||
|
def keys
|
||||||
|
@root.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
def values_at(*list)
|
||||||
|
@root.values_at(*list)
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_paths
|
def all_paths
|
||||||
|
Loading…
Reference in New Issue
Block a user