]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/aviator/feature/faraday/autoload.rb
Revert "add stackforge/keystone to 3rdparty"
[dsa-puppet.git] / 3rdparty / modules / aviator / feature / faraday / autoload.rb
1 module Faraday
2   # Internal: Adds the ability for other modules to manage autoloadable
3   # constants.
4   module AutoloadHelper
5     # Internal: Registers the constants to be auto loaded.
6     #
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
9     #           version.
10     # options - Hash of Symbol => String library names.
11     #
12     # Examples.
13     #
14     #   Faraday.autoload_all 'faraday/foo',
15     #     :Bar => 'bar'
16     #
17     #   # requires faraday/foo/bar to load Faraday::Bar.
18     #   Faraday::Bar
19     #
20     #
21     # Returns nothing.
22     def autoload_all(prefix, options)
23       if prefix =~ /^faraday(\/|$)/i
24         prefix = File.join(Faraday.root_path, prefix)
25       end
26       options.each do |const_name, path|
27         autoload const_name, File.join(prefix, path)
28       end
29     end
30
31     # Internal: Loads each autoloaded constant.  If thread safety is a concern,
32     # wrap this in a Mutex.
33     #
34     # Returns nothing.
35     def load_autoloaded_constants
36       constants.each do |const|
37         const_get(const) if autoload?(const)
38       end
39     end
40
41     # Internal: Filters the module's contents with those that have been already
42     # autoloaded.
43     #
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? }
48     end
49   end
50
51   class Adapter
52     extend AutoloadHelper
53     autoload_all 'faraday/adapter',
54       :NetHttp           => 'net_http',
55       :NetHttpPersistent => 'net_http_persistent',
56       :Typhoeus          => 'typhoeus',
57       :EMSynchrony       => 'em_synchrony',
58       :EMHttp            => 'em_http',
59       :Patron            => 'patron',
60       :Excon             => 'excon',
61       :Test              => 'test',
62       :Rack              => 'rack',
63       :HTTPClient        => 'httpclient'
64   end
65
66   class Request
67     extend AutoloadHelper
68     autoload_all 'faraday/request',
69       :UrlEncoded => 'url_encoded',
70       :Multipart => 'multipart',
71       :Retry => 'retry',
72       :Timeout => 'timeout',
73       :Authorization => 'authorization',
74       :BasicAuthentication => 'basic_authentication',
75       :TokenAuthentication => 'token_authentication',
76       :Instrumentation => 'instrumentation'
77   end
78
79   class Response
80     extend AutoloadHelper
81     autoload_all 'faraday/response',
82       :RaiseError => 'raise_error',
83       :Logger     => 'logger'
84   end
85 end