Skip to content

Commit

Permalink
Fully qualify constants to be checked
Browse files Browse the repository at this point in the history
  - This relates to the issue #974
  - This tries to make the single consistent fix mentioned in that ticket
  • Loading branch information
olleolleolle committed Feb 3, 2020
1 parent 099dd45 commit f799b53
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def self.default_connection_options=(options)
@default_connection_options = ConnectionOptions.from(options)
end

unless const_defined? :Timer
unless defined?(::Faraday::Timer)
require 'timeout'
Timer = Timeout
end
Expand Down
3 changes: 2 additions & 1 deletion lib/faraday/adapter/em_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def perform_request(env)

raise Faraday::ConnectionFailed, e
rescue StandardError => e
if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
if defined?(::OpenSSL::SSL::SSLError) && \
e.is_a?(::OpenSSL::SSL::SSLError)
raise Faraday::SSLError, e
end

Expand Down
3 changes: 2 additions & 1 deletion lib/faraday/adapter/httpclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def call(env)
rescue Errno::EADDRNOTAVAIL, Errno::ECONNREFUSED, IOError, SocketError
raise Faraday::ConnectionFailed, $ERROR_INFO
rescue StandardError => e
if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
if defined?(::OpenSSL::SSL::SSLError) && \
e.is_a?(::OpenSSL::SSL::SSLError)
raise Faraday::SSLError, e
end

Expand Down
6 changes: 4 additions & 2 deletions lib/faraday/adapter/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class NetHttp < Faraday::Adapter
Zlib::GzipFile::Error
]

exceptions << OpenSSL::SSL::SSLError if defined?(OpenSSL)
exceptions << Net::OpenTimeout if defined?(Net::OpenTimeout)
if defined?(::OpenSSL::SSL::SSLError)
exceptions << ::OpenSSL::SSL::SSLError
end
exceptions << ::Net::OpenTimeout if defined?(::Net::OpenTimeout)

NET_HTTP_EXCEPTIONS = exceptions.freeze

Expand Down
4 changes: 3 additions & 1 deletion lib/faraday/request/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module Faraday
class Request
# Request middleware for the Authorization HTTP header
class Authorization < Faraday::Middleware
KEY = 'Authorization' unless defined? KEY
unless defined?(::Faraday::Request::Authorization::KEY)
KEY = 'Authorization'
end

# @param type [String, Symbol]
# @param token [String, Symbol, Hash]
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/request/multipart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Request
# Middleware for supporting multi-part requests.
class Multipart < UrlEncoded
self.mime_type = 'multipart/form-data'
unless defined? DEFAULT_BOUNDARY_PREFIX
unless defined?(::Faraday::Request::Multipart::DEFAULT_BOUNDARY_PREFIX)
DEFAULT_BOUNDARY_PREFIX = '-----------RubyMultipartPost'
end

Expand Down
4 changes: 3 additions & 1 deletion lib/faraday/request/url_encoded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module Faraday
class Request
# Middleware for supporting urlencoded requests.
class UrlEncoded < Faraday::Middleware
CONTENT_TYPE = 'Content-Type' unless defined? CONTENT_TYPE
unless defined?(::Faraday::Request::UrlEncoded::CONTENT_TYPE)
CONTENT_TYPE = 'Content-Type'
end

class << self
attr_accessor :mime_type
Expand Down

0 comments on commit f799b53

Please sign in to comment.