Skip to content

Commit

Permalink
Deprecate three methods for version 2.0 (#1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyuraku committed Aug 22, 2022
1 parent 71dcb9c commit 2b1f331
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions lib/faraday/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,14 @@ def basic_auth(login, pass)
#
# @return [void]
def token_auth(token, options = nil)
warn <<~TEXT
WARNING: `Faraday::Connection#token_auth` is deprecated; it will be removed in version 2.0.
While initializing your connection, use `#request(:token_auth, ...)` instead.
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
TEXT
set_authorization_header(:token_auth, token, options)
end

deprecate :token_auth,
'#request(:token_auth, ...)',
'2.0',
'See https://lostisland.github.io/faraday/middleware/authentication for more usage info.'

# Sets up a custom Authorization header.
#
# @param type [String] authorization type
Expand All @@ -346,14 +346,14 @@ def token_auth(token, options = nil)
#
# @return [void]
def authorization(type, token)
warn <<~TEXT
WARNING: `Faraday::Connection#authorization` is deprecated; it will be removed in version 2.0.
While initializing your connection, use `#request(:authorization, ...)` instead.
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
TEXT
set_authorization_header(:authorization, type, token)
end

deprecate :authorization,
'#request(:authorization, ...)',
'2.0',
'See https://lostisland.github.io/faraday/middleware/authentication for more usage info.'

# Check if the adapter is parallel-capable.
#
# @yield if the adapter isn't parallel-capable, or if no adapter is set yet.
Expand Down
5 changes: 3 additions & 2 deletions lib/faraday/deprecate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def skip_during
# @param repl [#to_s, :none] the replacement to use, when `:none` it will
# alert the user that no replacement is present.
# @param ver [String] the semver the method will be removed.
def deprecate(name, repl, ver)
def deprecate(name, repl, ver, custom_message = nil)
class_eval do
gem_ver = Gem::Version.new(ver)
old = "_deprecated_#{name}"
Expand All @@ -95,7 +95,8 @@ def deprecate(name, repl, ver)
msg = [
"NOTE: #{target_message} is deprecated",
repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
"It will be removed in or after version #{gem_ver}",
"It will be removed in or after version #{gem_ver} ",
custom_message,
"\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
]
warn "#{msg.join}." unless Faraday::Deprecate.skip
Expand Down
7 changes: 3 additions & 4 deletions lib/faraday/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ def self.create(request_method)
end

def method
warn <<~TEXT
WARNING: `Faraday::Request##{__method__}` is deprecated; use `#http_method` instead. It will be removed in or after version 2.0.
`Faraday::Request##{__method__}` called from #{caller_locations(1..1).first}
TEXT
http_method
end

extend Faraday::Deprecate
deprecate :method, :http_method, '2.0'

# Replace params, preserving the existing hash type.
#
# @param hash [Hash] new params
Expand Down
2 changes: 1 addition & 1 deletion spec/faraday/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
describe 'deprecate method for HTTP method' do
let(:http_method) { :post }
let(:expected_warning) do
%r{WARNING: `Faraday::Request#method` is deprecated; use `#http_method` instead. It will be removed in or after version 2.0.\n`Faraday::Request#method` called from .+/spec/faraday/request_spec.rb:\d+.}
%r{NOTE: Faraday::Request#method is deprecated; use http_method instead\. It will be removed in or after version 2.0 \nFaraday::Request#method called from .+/spec/faraday/request_spec.rb:\d+.}
end

it { expect(subject.method).to eq(:post) }
Expand Down

0 comments on commit 2b1f331

Please sign in to comment.