Module: ActiveSupport::Dependencies::Loadable

Defined in:
activesupport/lib/active_support/dependencies.rb

Overview

Object includes this module

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exclude_from(base) ⇒ Object



201
202
203
# File 'activesupport/lib/active_support/dependencies.rb', line 201

def self.exclude_from(base)
  base.class_eval { define_method(:load, Kernel.instance_method(:load)) }
end

Instance Method Details

#load(file) ⇒ Object



232
233
234
235
236
# File 'activesupport/lib/active_support/dependencies.rb', line 232

def load(file, *)
  result = false
  load_dependency(file) { result = super }
  result
end

#load_dependency(file) ⇒ Object



221
222
223
224
225
226
227
228
229
230
# File 'activesupport/lib/active_support/dependencies.rb', line 221

def load_dependency(file)
  if Dependencies.load?
    Dependencies.new_constants_in(Object) { yield }.presence
  else
    yield
  end
rescue Exception => exception  # errors from loading file
  exception.blame_file! file
  raise
end

#require(file) ⇒ Object



238
239
240
241
242
# File 'activesupport/lib/active_support/dependencies.rb', line 238

def require(file, *)
  result = false
  load_dependency(file) { result = super }
  result
end

#require_association(file_name) ⇒ Object



217
218
219
# File 'activesupport/lib/active_support/dependencies.rb', line 217

def require_association(file_name)
  Dependencies.associate_with(file_name)
end

#require_dependency(file_name, message = "No such file to load -- %s") ⇒ Object



209
210
211
212
213
214
215
# File 'activesupport/lib/active_support/dependencies.rb', line 209

def require_dependency(file_name, message = "No such file to load -- %s")
  unless file_name.is_a?(String)
    raise ArgumentError, "the file name must be a String -- you passed #{file_name.inspect}"
  end

  Dependencies.depend_on(file_name, false, message)
end

#require_or_load(file_name) ⇒ Object



205
206
207
# File 'activesupport/lib/active_support/dependencies.rb', line 205

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.



257
258
259
# File 'activesupport/lib/active_support/dependencies.rb', line 257

def unloadable(const_desc)
  Dependencies.mark_for_unload const_desc
end