diff --git a/lib/faraday.rb b/lib/faraday.rb
index 1c0ba84af..80013c358 100644
--- a/lib/faraday.rb
+++ b/lib/faraday.rb
@@ -6,6 +6,24 @@
require 'faraday/middleware_registry'
require 'faraday/dependency_loader'
+unless defined?(::Faraday::Timer)
+ require 'timeout'
+ Timer = Timeout
+end
+
+require 'faraday/utils'
+require 'faraday/options'
+require 'faraday/connection'
+require 'faraday/rack_builder'
+require 'faraday/parameters'
+require 'faraday/middleware'
+require 'faraday/adapter'
+require 'faraday/request'
+require 'faraday/response'
+require 'faraday/error'
+require 'faraday/file_part'
+require 'faraday/param_part'
+
# This is the main namespace for Faraday.
#
# It provides methods to create {Connection} objects, and HTTP-related
@@ -107,6 +125,39 @@ def respond_to_missing?(symbol, include_private = false)
default_connection.respond_to?(symbol, include_private) || super
end
+ @ignore_env_proxy = false
+ @root_path = File.expand_path __dir__
+ @lib_path = File.expand_path 'faraday', __dir__
+ @default_adapter = :net_http
+
+ # @overload default_connection
+ # Gets the default connection used for simple scripts.
+ # @return [Faraday::Connection] a connection configured with
+ # the default_adapter.
+ # @overload default_connection=(connection)
+ # @param connection [Faraday::Connection]
+ # Sets the default {Faraday::Connection} for simple scripts that
+ # access the Faraday constant directly, such as
+ # Faraday.get "https://faraday.com"
.
+ def default_connection
+ @default_connection ||= Connection.new(default_connection_options)
+ end
+
+ # Gets the default connection options used when calling {Faraday#new}.
+ #
+ # @return [Faraday::ConnectionOptions]
+ def default_connection_options
+ @default_connection_options ||= ConnectionOptions.new
+ end
+
+ # Sets the default options used when calling {Faraday#new}.
+ #
+ # @param options [Hash, Faraday::ConnectionOptions]
+ def default_connection_options=(options)
+ @default_connection = nil
+ @default_connection_options = ConnectionOptions.from(options)
+ end
+
private
# Internal: Proxies method calls on the Faraday constant to
@@ -120,47 +171,5 @@ def method_missing(name, *args, &block)
end
end
- self.ignore_env_proxy = false
- self.root_path = File.expand_path __dir__
- self.lib_path = File.expand_path 'faraday', __dir__
- self.default_adapter = :net_http
-
- # @overload default_connection
- # Gets the default connection used for simple scripts.
- # @return [Faraday::Connection] a connection configured with
- # the default_adapter.
- # @overload default_connection=(connection)
- # @param connection [Faraday::Connection]
- # Sets the default {Faraday::Connection} for simple scripts that
- # access the Faraday constant directly, such as
- # Faraday.get "https://faraday.com"
.
- def self.default_connection
- @default_connection ||= Connection.new(default_connection_options)
- end
-
- # Gets the default connection options used when calling {Faraday#new}.
- #
- # @return [Faraday::ConnectionOptions]
- def self.default_connection_options
- @default_connection_options ||= ConnectionOptions.new
- end
-
- # Sets the default options used when calling {Faraday#new}.
- #
- # @param options [Hash, Faraday::ConnectionOptions]
- def self.default_connection_options=(options)
- @default_connection = nil
- @default_connection_options = ConnectionOptions.from(options)
- end
-
- unless defined?(::Faraday::Timer)
- require 'timeout'
- Timer = Timeout
- end
-
- require_libs 'utils', 'options', 'connection', 'rack_builder', 'parameters',
- 'middleware', 'adapter', 'request', 'response', 'error',
- 'file_part', 'param_part'
-
require_lib 'autoload' unless ENV['FARADAY_NO_AUTOLOAD']
end