Module: ActiveSupport::Dependencies::Loadable
- Defined in:
- lib/active_support/dependencies.rb
Overview
Object includes this module.
Class Method Summary collapse
-
.exclude_from(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #load_dependency(file) ⇒ Object
-
#require_dependency(file_name, message = "No such file to load -- %s.rb") ⇒ Object
Interprets a file using
mechanism
and marks its defined constants as autoloaded. - #require_or_load(file_name) ⇒ Object
-
#unloadable(const_desc) ⇒ Object
Mark the given constant as unloadable.
Class Method Details
Instance Method Details
#load_dependency(file) ⇒ Object
254 255 256 257 258 259 260 261 262 263 |
# File 'lib/active_support/dependencies.rb', line 254 def load_dependency(file) if Dependencies.load? && Dependencies.constant_watch_stack.watching? Dependencies.new_constants_in(Object) { yield } else yield end rescue Exception => exception # errors from loading file exception.blame_file! file if exception.respond_to? :blame_file! raise end |
#require_dependency(file_name, message = "No such file to load -- %s.rb") ⇒ Object
Interprets a file using mechanism
and marks its defined constants as autoloaded. file_name
can be either a string or respond to to_path
.
Use this method in code that absolutely needs a certain constant to be defined at that point. A typical use case is to make constant name resolution deterministic for constants with the same relative name in different namespaces whose evaluation would depend on load order otherwise.
245 246 247 248 249 250 251 252 |
# File 'lib/active_support/dependencies.rb', line 245 def require_dependency(file_name, = "No such file to load -- %s.rb") file_name = file_name.to_path if file_name.respond_to?(:to_path) unless file_name.is_a?(String) raise ArgumentError, "the file name must either be a String or implement #to_path -- you passed #{file_name.inspect}" end Dependencies.depend_on(file_name, ) end |
#require_or_load(file_name) ⇒ Object
232 233 234 |
# File 'lib/active_support/dependencies.rb', line 232 def require_or_load(file_name) Dependencies.require_or_load(file_name) end |
#unloadable(const_desc) ⇒ Object
Mark the given constant as unloadable. Unloadable constants are removed each time dependencies are cleared.
Note that marking a constant for unloading need only be done once. Setup or init scripts may list each unloadable constant that may need unloading; each constant will be removed for every subsequent clear, as opposed to for the first clear.
The provided constant descriptor may be a (non-anonymous) module or class, or a qualified constant name as a string or symbol.
Returns true
if the constant was not previously marked for unloading, false
otherwise.
278 279 280 |
# File 'lib/active_support/dependencies.rb', line 278 def unloadable(const_desc) Dependencies.mark_for_unload const_desc end |