Module: Faraday::AutoloadHelper
Overview
Internal: Adds the ability for other modules to manage autoloadable constants.
Instance Method Summary collapse
-
#all_loaded_constants ⇒ Object
Internal: Filters the module’s contents with those that have been already autoloaded.
-
#autoload_all(prefix, options) ⇒ Object
Internal: Registers the constants to be auto loaded.
-
#load_autoloaded_constants ⇒ Object
Internal: Loads each autoloaded constant.
Instance Method Details
#all_loaded_constants ⇒ Object
Internal: Filters the module’s contents with those that have been already autoloaded.
Returns an Array of Class/Module objects.
45 46 47 48 |
# File 'lib/faraday/autoload.rb', line 45 def all_loaded_constants constants.map { |c| const_get(c) }. select { |a| a.respond_to?(:loaded?) && a.loaded? } end |
#autoload_all(prefix, options) ⇒ Object
Internal: Registers the constants to be auto loaded.
prefix - The String require prefix. If the path is inside Faraday, then
it will be prefixed with the root path of this loaded Faraday
version.
options - Hash of Symbol => String library names.
Examples.
Faraday.autoload_all 'faraday/foo',
:Bar => 'bar'
# requires faraday/foo/bar to load Faraday::Bar.
Faraday::Bar
Returns nothing.
22 23 24 25 26 27 28 29 |
# File 'lib/faraday/autoload.rb', line 22 def autoload_all(prefix, ) if prefix =~ /^faraday(\/|$)/i prefix = File.join(Faraday.root_path, prefix) end .each do |const_name, path| autoload const_name, File.join(prefix, path) end end |
#load_autoloaded_constants ⇒ Object
Internal: Loads each autoloaded constant. If thread safety is a concern, wrap this in a Mutex.
Returns nothing.
35 36 37 38 39 |
# File 'lib/faraday/autoload.rb', line 35 def load_autoloaded_constants constants.each do |const| const_get(const) if autoload?(const) end end |