Skip to content

Commit 2b1f331

Browse files
authored
Deprecate three methods for version 2.0 (#1446)
1 parent 71dcb9c commit 2b1f331

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

lib/faraday/connection.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ def basic_auth(login, pass)
319319
#
320320
# @return [void]
321321
def token_auth(token, options = nil)
322-
warn <<~TEXT
323-
WARNING: `Faraday::Connection#token_auth` is deprecated; it will be removed in version 2.0.
324-
While initializing your connection, use `#request(:token_auth, ...)` instead.
325-
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
326-
TEXT
327322
set_authorization_header(:token_auth, token, options)
328323
end
329324

325+
deprecate :token_auth,
326+
'#request(:token_auth, ...)',
327+
'2.0',
328+
'See https://lostisland.github.io/faraday/middleware/authentication for more usage info.'
329+
330330
# Sets up a custom Authorization header.
331331
#
332332
# @param type [String] authorization type
@@ -346,14 +346,14 @@ def token_auth(token, options = nil)
346346
#
347347
# @return [void]
348348
def authorization(type, token)
349-
warn <<~TEXT
350-
WARNING: `Faraday::Connection#authorization` is deprecated; it will be removed in version 2.0.
351-
While initializing your connection, use `#request(:authorization, ...)` instead.
352-
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
353-
TEXT
354349
set_authorization_header(:authorization, type, token)
355350
end
356351

352+
deprecate :authorization,
353+
'#request(:authorization, ...)',
354+
'2.0',
355+
'See https://lostisland.github.io/faraday/middleware/authentication for more usage info.'
356+
357357
# Check if the adapter is parallel-capable.
358358
#
359359
# @yield if the adapter isn't parallel-capable, or if no adapter is set yet.

lib/faraday/deprecate.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def skip_during
7878
# @param repl [#to_s, :none] the replacement to use, when `:none` it will
7979
# alert the user that no replacement is present.
8080
# @param ver [String] the semver the method will be removed.
81-
def deprecate(name, repl, ver)
81+
def deprecate(name, repl, ver, custom_message = nil)
8282
class_eval do
8383
gem_ver = Gem::Version.new(ver)
8484
old = "_deprecated_#{name}"
@@ -95,7 +95,8 @@ def deprecate(name, repl, ver)
9595
msg = [
9696
"NOTE: #{target_message} is deprecated",
9797
repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
98-
"It will be removed in or after version #{gem_ver}",
98+
"It will be removed in or after version #{gem_ver} ",
99+
custom_message,
99100
"\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
100101
]
101102
warn "#{msg.join}." unless Faraday::Deprecate.skip

lib/faraday/request.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ def self.create(request_method)
5858
end
5959

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

64+
extend Faraday::Deprecate
65+
deprecate :method, :http_method, '2.0'
66+
6867
# Replace params, preserving the existing hash type.
6968
#
7069
# @param hash [Hash] new params

spec/faraday/request_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
describe 'deprecate method for HTTP method' do
2626
let(:http_method) { :post }
2727
let(:expected_warning) do
28-
%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+.}
28+
%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+.}
2929
end
3030

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

0 commit comments

Comments
 (0)