class Root
Ruby on Rails 7.2.3
Since v3.0.20This 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 through 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 above command creates a new root object and adds “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 enumerable and allows you to easily add extra paths:
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.
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.
Inherits from
Attributes
Methods (defined here)
- # []
- # []=
- # add
- # all_paths
- # autoload_once
- # autoload_paths
- # eager_load
- # keys
- # load_paths
- # values
- # values_at
- self. new
Private methods
(1)
Implementation detail — not part of the public API.
Methods (inherited)
From Object (17)
- # acts_like?
- # blank?
- # deep_dup
- # duplicable?
- # html_safe?
- # in?
- # instance_values
- # instance_variable_names
- # presence
- # presence_in
- # present?
- # to_param
- # to_query
- # try
- # try!
- # with
- # with_options
From ActiveSupport::NumericWithFormat (2)
- # to_formatted_s
- # to_fs