2 # Internal: Adds the ability for other modules to manage autoloadable
5 # Internal: Registers the constants to be auto loaded.
7 # prefix - The String require prefix. If the path is inside Faraday, then
8 # it will be prefixed with the root path of this loaded Faraday
10 # options - Hash of Symbol => String library names.
14 # Faraday.autoload_all 'faraday/foo',
17 # # requires faraday/foo/bar to load Faraday::Bar.
22 def autoload_all(prefix, options)
23 if prefix =~ /^faraday(\/|$)/i
24 prefix = File.join(Faraday.root_path, prefix)
26 options.each do |const_name, path|
27 autoload const_name, File.join(prefix, path)
31 # Internal: Loads each autoloaded constant. If thread safety is a concern,
32 # wrap this in a Mutex.
35 def load_autoloaded_constants
36 constants.each do |const|
37 const_get(const) if autoload?(const)
41 # Internal: Filters the module's contents with those that have been already
44 # Returns an Array of Class/Module objects.
45 def all_loaded_constants
46 constants.map { |c| const_get(c) }.
47 select { |a| a.respond_to?(:loaded?) && a.loaded? }
53 autoload_all 'faraday/adapter',
54 :NetHttp => 'net_http',
55 :NetHttpPersistent => 'net_http_persistent',
56 :Typhoeus => 'typhoeus',
57 :EMSynchrony => 'em_synchrony',
63 :HTTPClient => 'httpclient'
68 autoload_all 'faraday/request',
69 :UrlEncoded => 'url_encoded',
70 :Multipart => 'multipart',
72 :Timeout => 'timeout',
73 :Authorization => 'authorization',
74 :BasicAuthentication => 'basic_authentication',
75 :TokenAuthentication => 'token_authentication',
76 :Instrumentation => 'instrumentation'
81 autoload_all 'faraday/response',
82 :RaiseError => 'raise_error',