module Faraday::AutoloadHelper

Adds the ability for other modules to manage autoloadable constants.

@api private

Public Instance Methods

all_loaded_constants() click to toggle source

Filters the module's contents with those that have been already autoloaded.

@return [Array<Class, Module>]

# File lib/faraday/autoload.rb, line 49
def all_loaded_constants
  constants
    .map { |c| const_get(c) }
    .select { |a| a.respond_to?(:loaded?) && a.loaded? }
end
autoload_all(prefix, options) click to toggle source

Registers the constants to be auto loaded.

@param prefix [String] The require prefix. If the path is inside Faraday,

then it will be prefixed with the root path of this loaded
Faraday version.

@param options [{ Symbol => String }] library names.

@example

Faraday.autoload_all 'faraday/foo',
  Bar: 'bar'

# requires faraday/foo/bar to load Faraday::Bar.
Faraday::Bar

@return [void]

# File lib/faraday/autoload.rb, line 25
def autoload_all(prefix, options)
  if prefix.match? %r{^faraday(/|$)}i
    prefix = File.join(Faraday.root_path, prefix)
  end

  options.each do |const_name, path|
    autoload const_name, File.join(prefix, path)
  end
end
load_autoloaded_constants() click to toggle source

Loads each autoloaded constant. If thread safety is a concern, wrap this in a Mutex.

@return [void]

# File lib/faraday/autoload.rb, line 39
def load_autoloaded_constants
  constants.each do |const|
    const_get(const) if autoload?(const)
  end
end