class Rails::Paths::Root
Check the Rails::Paths::Path
documentation for more information.<br><br>root.existent # => [“/rails/app/controllers”]<br>root.expanded # => [“/rails/app/controllers”]
root.add “app/controllers”
root = Root.new “/rails”
Finally, the Path
object also provides a few helpers:
eager_load, autoload, autoload_once and glob.
The add
method accepts the following options as arguments:<br><br>root.inspect # => [“config/routes.rb”]
root.add “config/routes”, :with => “config/routes.rb”
you may not want this behavior, so you can give :with as option.
contains the path with the same path value given to add
. In some situations,
Notice that when you add a path using add
, the path object created already
path.inspect # => [“app/controllers”, “lib/controllers”]
path << “lib/controllers”
path.inspect # => [“app/controllers”]
path.is_a?(Array) # => true
The Path
object is simply an array and allows you to easily add extra paths:
path.is_a?(Rails::Paths::Path) # => true
path.eager_load? # => true
path = root[“app/controllers”]
This means we can get a Rails::Paths::Path
object back like below:
The command above creates a new root object and add “app/controllers” as a path.
root.add “app/controllers”, :eager_load => true
root = Root.new “/rails”
paths by a Hash like API. It requires you to give a physical path on initialization.
It allows you to collect information about how you want to structure your application
This object is an extended hash that behaves as root of the Rails::Paths
system.
def []=(path, value)
def []=(path, value) value = Path.new(self, path, value) unless value.is_a?(Path) super(path, value) end
def add(path, options={})
def add(path, options={}) with = options[:with] || path self[path] = Path.new(self, path, with, options) end
def all_paths
def all_paths values.tap { |v| v.uniq! } end
def autoload_once
def autoload_once filter_by(:autoload_once?) end
def autoload_paths
def autoload_paths filter_by(:autoload?) end
def eager_load
def eager_load filter_by(:eager_load?) end
def filter_by(constraint)
def filter_by(constraint) all = [] all_paths.each do |path| if path.send(constraint) paths = path.existent paths -= path.children.map { |p| p.send(constraint) ? [] : p.existent }.flatten all.concat(paths) end end all.uniq! all end
def initialize(path)
def initialize(path) raise "Argument should be a String of the physical root path" if path.is_a?(Array) @current = nil @path = path @root = self super() end
def load_paths
def load_paths filter_by(:load_path?) end