Class Dependencies::LoadingModule
In: vendor/activesupport/lib/active_support/dependencies.rb
Parent: Module

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

path  [R] 
root  [R] 

Public Class methods

[Source]

    # File vendor/activesupport/lib/active_support/dependencies.rb, line 61
61:     def initialize(root, path=[])
62:       @path = path.clone.freeze
63:       @root = root
64:     end

[Source]

    # File vendor/activesupport/lib/active_support/dependencies.rb, line 57
57:     def self.root(*load_paths)
58:       RootLoadingModule.new(*load_paths)
59:     end

Public Instance methods

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

[Source]

     # File vendor/activesupport/lib/active_support/dependencies.rb, line 105
105:     def const_available?(name)
106:       self.const_defined?(name) || load_paths.any? {|lp| lp.filesystem_path(path + [name])}
107:     end

Load the controller class or a parent module.

[Source]

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

Load missing constants if possible.

[Source]

    # File vendor/activesupport/lib/active_support/dependencies.rb, line 70
70:     def const_missing(name)
71:       const_load!(name) ? const_get(name) : super(name)
72:     end

[Source]

    # File vendor/activesupport/lib/active_support/dependencies.rb, line 67
67:     def load_paths() self.root.load_paths end

[Source]

    # File vendor/activesupport/lib/active_support/dependencies.rb, line 66
66:     def root?() self.root == self end

[Validate]