This object is an extended hash that behaves as root of the Rails::Paths system. It allows you to collect information about how you want to structure your application paths by a Hash like API. It requires you to give a physical path on initialization.

  root = Root.new "/rails"
  root.add "app/controllers", :eager_load => true

The command above creates a new root object and add “app/controllers“ as a path. This means we can get a +Rails::Paths::Path+ object back like below:

  path = root["app/controllers"]
  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:

  path.is_a?(Array) # => true
  path.inspect      # => ["app/controllers"]

  path << "lib/controllers"
  path.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, you may not want this behavior, so you can give :with as option.

  root.add "config/routes", :with => "config/routes.rb"
  root["config/routes"].inspect # => ["config/routes.rb"]

The add method accepts the following options as arguments: eager_load, autoload, autoload_once and glob.

Finally, the Path object also provides a few helpers:

  root = Root.new "/rails"
  root.add "app/controllers"

  root["app/controllers"].expanded # => ["/rails/app/controllers"]
  root["app/controllers"].existent # => ["/rails/app/controllers"]

Check the Rails::Paths::Path documentation for more information.

Methods
#
A
E
F
L
N
Attributes
[RW] path
Class Public methods
new(path)
    # File railties/lib/rails/paths.rb, line 49
49:       def initialize(path)
50:         raise "Argument should be a String of the physical root path" if path.is_a?(Array)
51:         @current = nil
52:         @path = path
53:         @root = self
54:         super()
55:       end
Instance Public methods
[]=(path, value)
    # File railties/lib/rails/paths.rb, line 57
57:       def []=(path, value)
58:         value = Path.new(self, path, value) unless value.is_a?(Path)
59:         super(path, value)
60:       end
add(path, options={})
    # File railties/lib/rails/paths.rb, line 62
62:       def add(path, options={})
63:         with = options[:with] || path
64:         self[path] = Path.new(self, path, with, options)
65:       end
all_paths()
    # File railties/lib/rails/paths.rb, line 67
67:       def all_paths
68:         values.tap { |v| v.uniq! }
69:       end
autoload_once()
    # File railties/lib/rails/paths.rb, line 71
71:       def autoload_once
72:         filter_by(:autoload_once?)
73:       end
autoload_paths()
    # File railties/lib/rails/paths.rb, line 79
79:       def autoload_paths
80:         filter_by(:autoload?)
81:       end
eager_load()
    # File railties/lib/rails/paths.rb, line 75
75:       def eager_load
76:         filter_by(:eager_load?)
77:       end
load_paths()
    # File railties/lib/rails/paths.rb, line 83
83:       def load_paths
84:         filter_by(:load_path?)
85:       end
Instance Protected methods
filter_by(constraint)
     # File railties/lib/rails/paths.rb, line 89
 89:       def filter_by(constraint)
 90:         all = []
 91:         all_paths.each do |path|
 92:           if path.send(constraint)
 93:             paths  = path.existent
 94:             paths -= path.children.map { |p| p.send(constraint) ? [] : p.existent }.flatten
 95:             all.concat(paths)
 96:           end
 97:         end
 98:         all.uniq!
 99:         all
100:       end