class Root
Ruby on Rails 3.1.12
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 by a Hash like API. It requires you to give a physical path on initialization.
root = Root.new 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 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 root.path = "/rails" root.add "app/controllers" root["app/controllers"].expanded # => ["/rails/app/controllers"] root["app/controllers"].existent # => ["/rails/app/controllers"]
Check the Path documentation for more information.
Inherits from
Attributes
Methods (defined here)
- # []=
- # add
- # all_paths
- # autoload_once
- # autoload_paths
- # eager_load
- # filter_by
- # load_paths
- self. new
Methods (inherited)
From Hash (28)
- # assert_valid_keys
- # deep_dup
- # deep_merge
- # deep_merge!
- # diff
- # encode_json
- # except
- # except!
- # extract!
- # extractable_options?
- # nested_under_indifferent_access
- # reverse_merge
- # reverse_merge!
- # reverse_update
- # slice
- # slice!
- # stringify_keys
- # stringify_keys!
- # symbolize_keys
- # symbolize_keys!
- # to_options
- # to_options!
- # to_param
- # to_query
- # to_xml
- # with_indifferent_access
- self. from_trusted_xml
- self. from_xml
From Object (24)
- # acts_like?
- # app
- # blank?
- # controller
- # create_fixtures
- # duplicable?
- # helper
- # html_safe?
- # in?
- # index
- # instance_variable_names
- # new_session
- # options
- # presence
- # present?
- # reload!
- # show
- # test_homepage
- # to_param
- # to_query
- # try
- # unescape
- # with_options
- self. table_name_prefix