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
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"]
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.