LoadingModules implement namespace-safe dynamic loading. They support automatic loading via const_missing, allowing contained items to be automatically loaded when required. No extra syntax is required, as expressions such as Controller::Admin::UserController load the relavent files automatically.

Ruby-style modules are supported, as a folder named ‘submodule’ will load ‘submodule.rb’ when available.

Methods
Attributes
[R] path
[R] root
Public Class methods
new(root, path=[])
    # File vendor/rails/activesupport/lib/active_support/dependencies.rb, line 59
59:     def initialize(root, path=[])
60:       @path = path.clone.freeze
61:       @root = root
62:     end
root(*load_paths)
    # File vendor/rails/activesupport/lib/active_support/dependencies.rb, line 55
55:     def self.root(*load_paths)
56:       RootLoadingModule.new(*load_paths)
57:     end
Public Instance methods
const_available?(name)

Is this name present or loadable? This method is used by Routes to find valid controllers.

     # File vendor/rails/activesupport/lib/active_support/dependencies.rb, line 103
103:     def const_available?(name)
104:       self.const_defined?(name) || load_paths.any? {|lp| lp.filesystem_path(path + [name])}
105:     end
const_load!(name, file_name = nil)

Load the controller class or a parent module.

    # File vendor/rails/activesupport/lib/active_support/dependencies.rb, line 73
73:     def const_load!(name, file_name = nil)
74:       path = self.path + [file_name || name]
75: 
76:       load_paths.each do |load_path|
77:         fs_path = load_path.filesystem_path(path)
78:         next unless fs_path
79: 
80:         if File.directory?(fs_path)
81:           new_module = LoadingModule.new(self.root, self.path + [name])
82:           self.const_set name, new_module
83:           if self.root?
84:             raise NameError, "Cannot load controller module named #{name}: An object of type #{Object.const_get(name).class.to_s} already exists." \
85:               if Object.const_defined?(name)
86:             Object.const_set(name, new_module) 
87:           end
88:           break
89:         elsif File.file?(fs_path)
90:           self.root.load_file!(fs_path)
91:           
92:           # Import the loaded constant from Object provided we are the root node.
93:           self.const_set(name, Object.const_get(name)) if self.root? && Object.const_defined?(name)
94:           break
95:         end
96:       end
97: 
98:       return self.const_defined?(name)
99:     end
const_missing(name)

Load missing constants if possible.

    # File vendor/rails/activesupport/lib/active_support/dependencies.rb, line 68
68:     def const_missing(name)
69:       const_load!(name) ? const_get(name) : super(name)
70:     end
load_paths()
    # File vendor/rails/activesupport/lib/active_support/dependencies.rb, line 65
65:     def load_paths() self.root.load_paths end
root?()
    # File vendor/rails/activesupport/lib/active_support/dependencies.rb, line 64
64:     def root?() self.root == self end