Type:
Class

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.

1
2
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:

1
2
3
path = root["app/controllers"]
path.eager_load?               # => true
path.is_a?(Rails::Paths::Path) # => true

The Path object is simply an enumerable and allows you to easily add extra paths:

1
2
3
4
5
path.is_a?(Enumerable) # => true
path.to_ary.inspect    # => ["app/controllers"]
 
path << "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, you may not want this behavior, so you can give :with as option.

1
2
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:

1
2
3
4
5
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.

[]=
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

[]=(path, value) Instance Public methods

2025-01-10 15:47:30
add
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

add(path, options = {}) Instance Public methods

2025-01-10 15:47:30
eager_load
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

eager_load() Instance Public methods

2025-01-10 15:47:30
keys
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

keys() Instance Public methods

2025-01-10 15:47:30
[]
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

[](path) Instance Public methods

2025-01-10 15:47:30
values_at
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

values_at(*list) Instance Public methods

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

new(path) Class Public methods

2025-01-10 15:47:30
autoload_once
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

autoload_once() Instance Public methods

2025-01-10 15:47:30
all_paths
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

all_paths() Instance Public methods

2025-01-10 15:47:30
values
  • References/Ruby on Rails/Rails/Classes/Rails/Rails::Paths/Rails::Paths::Root

values() Instance Public methods

2025-01-10 15:47:30