method
load_missing_constant
v3.2.13 -
Show latest stable
- Class:
ActiveSupport::Dependencies
load_missing_constant(from_mod, const_name)public
Load the constant named const_name which is missing from from_mod. If it is not possible to load the constant into from_mod, try its parent module using const_missing.
# File activesupport/lib/active_support/dependencies.rb, line 487
def load_missing_constant(from_mod, const_name)
log_call from_mod, const_name
unless qualified_const_defined?(from_mod.name) && Inflector.constantize(from_mod.name).equal?(from_mod)
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
end
raise NameError, "#{from_mod} is not missing constant #{const_name}!" if local_const_defined?(from_mod, const_name)
qualified_name = qualified_name_for from_mod, const_name
path_suffix = qualified_name.underscore
file_path = search_for_file(path_suffix)
if file_path && ! loaded.include?(File.expand_path(file_path).sub(/\.rb\z/, '')) # We found a matching file to load
require_or_load file_path
raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless local_const_defined?(from_mod, const_name)
return from_mod.const_get(const_name)
elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
return mod
elsif (parent = from_mod.parent) && parent != from_mod &&
! from_mod.parents.any? { |p| local_const_defined?(p, const_name) }
# If our parents do not have a constant named +const_name+ then we are free
# to attempt to load upwards. If they do have such a constant, then this
# const_missing must be due to from_mod::const_name, which should not
# return constants from from_mod's parents.
begin
return parent.const_missing(const_name)
rescue NameError => e
raise unless e.missing_name? qualified_name_for(parent, const_name)
end
end
raise NameError,
"uninitialized constant #{qualified_name}",
caller.reject {|l| l.starts_with? __FILE__ }
end Related methods
- Instance methods
- associate_with
- autoload_module!
- autoloadable_module?
- autoloaded?
- clear
- constantize
- depend_on
- hook!
- load?
- load_file
- load_missing_constant
- load_once_path?
- loadable_constants_for_path
- local_const_defined?
- mark_for_unload
- new_constants_in
- qualified_const_defined?
- qualified_name_for
- reference
- remove_constant
- remove_unloadable_constants!
- require_or_load
- safe_constantize
- search_for_file
- to_constant_name
- unhook!
- will_unload?
- Protected methods
-
log -
log_activity? -
log_call