Class: Rails::Paths::Root
- Includes:
- PathParent
- Defined in:
- railties/lib/rails/paths.rb
Overview
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
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"]. # => ["/rails/app/controllers"]
root["app/controllers"].existent # => ["/rails/app/controllers"]
Check the Path documentation for more information.
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #[]=(path, value) ⇒ Object
- #add(path, options = {}) ⇒ Object
- #all_paths ⇒ Object
- #autoload_once ⇒ Object
- #autoload_paths ⇒ Object
- #eager_load ⇒ Object
-
#initialize(path) ⇒ Root
constructor
A new instance of Root.
- #load_paths ⇒ Object
Methods included from PathParent
Methods inherited from Hash
#as_json, #assert_valid_keys, #deep_dup, #deep_merge, #deep_merge!, #diff, #encode_json, #except, #except!, #extract!, #extractable_options?, from_xml, #reverse_merge, #reverse_merge!, #slice, #slice!, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_param, #to_xml, #with_indifferent_access
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rails::Paths::PathParent
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path
67 68 69 |
# File 'railties/lib/rails/paths.rb', line 67 def path @path end |
Instance Method Details
#[]=(path, value) ⇒ Object
77 78 79 80 |
# File 'railties/lib/rails/paths.rb', line 77 def []=(path, value) value = Path.new(self, path, value) unless value.is_a?(Path) super(path, value) end |
#add(path, options = {}) ⇒ Object
82 83 84 85 |
# File 'railties/lib/rails/paths.rb', line 82 def add(path, ={}) with = [:with] || path self[path] = Path.new(self, path, with, ) end |
#all_paths ⇒ Object
87 88 89 |
# File 'railties/lib/rails/paths.rb', line 87 def all_paths values.tap { |v| v.uniq! } end |
#autoload_once ⇒ Object
91 92 93 |
# File 'railties/lib/rails/paths.rb', line 91 def autoload_once filter_by(:autoload_once?) end |
#autoload_paths ⇒ Object
99 100 101 |
# File 'railties/lib/rails/paths.rb', line 99 def autoload_paths filter_by(:autoload?) end |
#eager_load ⇒ Object
95 96 97 |
# File 'railties/lib/rails/paths.rb', line 95 def eager_load filter_by(:eager_load?) end |
#load_paths ⇒ Object
103 104 105 |
# File 'railties/lib/rails/paths.rb', line 103 def load_paths filter_by(:load_path?) end |