faraday 0.17.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +216 -0
- data/Rakefile +13 -0
- data/lib/faraday.rb +1 -1
- data/lib/faraday/adapter/em_http.rb +9 -9
- data/lib/faraday/adapter/em_synchrony.rb +5 -5
- data/lib/faraday/adapter/excon.rb +3 -3
- data/lib/faraday/adapter/httpclient.rb +4 -4
- data/lib/faraday/adapter/net_http.rb +2 -2
- data/lib/faraday/adapter/net_http_persistent.rb +3 -3
- data/lib/faraday/adapter/patron.rb +5 -5
- data/lib/faraday/adapter/rack.rb +1 -1
- data/lib/faraday/deprecate.rb +101 -0
- data/lib/faraday/error.rb +85 -32
- data/lib/faraday/options.rb +1 -1
- data/lib/faraday/request/retry.rb +6 -5
- data/lib/faraday/response.rb +3 -3
- data/lib/faraday/response/raise_error.rb +7 -3
- data/spec/faraday/deprecate_spec.rb +69 -0
- data/spec/faraday/error_spec.rb +102 -0
- data/spec/faraday/response/raise_error_spec.rb +95 -0
- data/spec/spec_helper.rb +104 -0
- data/test/adapters/default_test.rb +14 -0
- data/test/adapters/em_http_test.rb +30 -0
- data/test/adapters/em_synchrony_test.rb +32 -0
- data/test/adapters/excon_test.rb +30 -0
- data/test/adapters/httpclient_test.rb +34 -0
- data/test/adapters/integration.rb +263 -0
- data/test/adapters/logger_test.rb +136 -0
- data/test/adapters/net_http_persistent_test.rb +114 -0
- data/test/adapters/net_http_test.rb +79 -0
- data/test/adapters/patron_test.rb +40 -0
- data/test/adapters/rack_test.rb +38 -0
- data/test/adapters/test_middleware_test.rb +157 -0
- data/test/adapters/typhoeus_test.rb +38 -0
- data/test/authentication_middleware_test.rb +65 -0
- data/test/composite_read_io_test.rb +109 -0
- data/test/connection_test.rb +738 -0
- data/test/env_test.rb +268 -0
- data/test/helper.rb +75 -0
- data/test/live_server.rb +67 -0
- data/test/middleware/instrumentation_test.rb +88 -0
- data/test/middleware/retry_test.rb +282 -0
- data/test/middleware_stack_test.rb +260 -0
- data/test/multibyte.txt +1 -0
- data/test/options_test.rb +333 -0
- data/test/parameters_test.rb +157 -0
- data/test/request_middleware_test.rb +126 -0
- data/test/response_middleware_test.rb +72 -0
- data/test/strawberry.rb +2 -0
- data/test/utils_test.rb +98 -0
- metadata +47 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16a3bb1447dde55604486c5a3a912281318ca8d0a211008623bcafb270a104ea
|
4
|
+
data.tar.gz: 966aaefe77900eab1bd1687bf7ce57950e0dbc8fb8dcd7a062fddf6be4393c4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b016c9c3ea03bba4a9a40325f0494ef8a096e6c67d46ced7cb13da8e2bfeafca92107bc971f276ea883249219e13fa3f5f67e6c73d43c6ce66c6827108457e86
|
7
|
+
data.tar.gz: 23e0a83830645895da998a9961d43747de7da1ee9428ea15a68776e1edb346f67c1b66d9403f3e4e0b5c40790e6adbf9bfa8dbb26db0cf79d4fafcb292c9e7ff
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
# Faraday Changelog
|
2
|
+
|
3
|
+
## v0.17.1
|
4
|
+
|
5
|
+
Final release before Faraday v1.0, with important fixes for Ruby 2.7.
|
6
|
+
|
7
|
+
Fixes:
|
8
|
+
|
9
|
+
* RaiseError response middleware raises exception if HTTP client returns a nil
|
10
|
+
status. (#1042)
|
11
|
+
|
12
|
+
Misc:
|
13
|
+
|
14
|
+
* Fix Ruby 2.7 warnings (#1009)
|
15
|
+
* Add `Faraday::Deprecate` to warn about upcoming v1.0 changes. (#1054, #1059,
|
16
|
+
#1076, #1077)
|
17
|
+
* Add release notes up to current in CHANGELOG.md (#1066)
|
18
|
+
* Port minimal rspec suite from main branch to run backported tests. (#1058)
|
19
|
+
|
20
|
+
## v0.17.0
|
21
|
+
|
22
|
+
This release is the same as v0.15.4. It was pushed to cover up releases
|
23
|
+
v0.16.0-v0.16.2.
|
24
|
+
|
25
|
+
## v0.15.4
|
26
|
+
|
27
|
+
* Expose `pool_size` as a option for the NetHttpPersistent adapter (#834)
|
28
|
+
|
29
|
+
## v0.15.3
|
30
|
+
|
31
|
+
* Make Faraday::Request serialisable with Marshal. (#803)
|
32
|
+
* Add DEFAULT_EXCEPTIONS constant to Request::Retry (#814)
|
33
|
+
* Add support for Ruby 2.6 Net::HTTP write_timeout (#824)
|
34
|
+
|
35
|
+
## v0.15.2
|
36
|
+
|
37
|
+
* Prevents `Net::HTTP` adapters to retry request internally by setting `max_retries` to 0 if available (Ruby 2.5+). (#799)
|
38
|
+
* Fixes `NestedParamsEncoder` handling of empty array values (#801)
|
39
|
+
|
40
|
+
## v0.15.1
|
41
|
+
|
42
|
+
* NetHttpPersistent adapter better reuse of SSL connections (#793)
|
43
|
+
* Refactor: inline cached_connection (#797)
|
44
|
+
* Logger middleware: use $stdout instead of STDOUT (#794)
|
45
|
+
* Fix: do not memoize/reuse Patron session (#796)
|
46
|
+
|
47
|
+
Also in this release:
|
48
|
+
|
49
|
+
* Allow setting min/max ssl version for Net::HTTP (#792)
|
50
|
+
* Allow setting min/max ssl version for Excon (#795)
|
51
|
+
|
52
|
+
## v0.15.0
|
53
|
+
|
54
|
+
Features:
|
55
|
+
|
56
|
+
* Added retry block option to retry middleware. (#770)
|
57
|
+
* Retry middleware improvements (honour Retry-After header, retry statuses) (#773)
|
58
|
+
* Improve response logger middleware output (#784)
|
59
|
+
|
60
|
+
Fixes:
|
61
|
+
|
62
|
+
* Remove unused class error (#767)
|
63
|
+
* Fix minor typo in README (#760)
|
64
|
+
* Reuse persistent connections when using net-http-persistent (#778)
|
65
|
+
* Fix Retry middleware documentation (#781)
|
66
|
+
* Returns the http response when giving up on retrying by status (#783)
|
67
|
+
|
68
|
+
## v0.14.0
|
69
|
+
|
70
|
+
Features:
|
71
|
+
|
72
|
+
* Allow overriding env proxy (#754)
|
73
|
+
* Remove legacy Typhoeus adapter (#715)
|
74
|
+
* External Typhoeus Adapter Compatibility (#748)
|
75
|
+
* Warn about missing adapter when making a request (#743)
|
76
|
+
* Faraday::Adapter::Test stubs now support entire urls (with host) (#741)
|
77
|
+
|
78
|
+
Fixes:
|
79
|
+
|
80
|
+
* If proxy is manually provided, this takes priority over `find_proxy` (#724)
|
81
|
+
* Fixes the behaviour for Excon's open_timeout (not setting write_timeout anymore) (#731)
|
82
|
+
* Handle all connection timeout messages in Patron (#687)
|
83
|
+
|
84
|
+
## v0.13.1
|
85
|
+
|
86
|
+
* Fixes an incompatibility with Addressable::URI being used as uri_parser
|
87
|
+
|
88
|
+
## v0.13.0
|
89
|
+
|
90
|
+
Features:
|
91
|
+
|
92
|
+
* Dynamically reloads the proxy when performing a request on an absolute domain (#701)
|
93
|
+
* Adapter support for Net::HTTP::Persistent v3.0.0 (#619)
|
94
|
+
|
95
|
+
Fixes:
|
96
|
+
|
97
|
+
* Prefer #hostname over #host. (#714)
|
98
|
+
* Fixes an edge-case issue with response headers parsing (missing HTTP header) (#719)
|
99
|
+
|
100
|
+
## v0.12.2
|
101
|
+
|
102
|
+
* Parse headers from aggregated proxy requests/responses (#681)
|
103
|
+
* Guard against invalid middleware configuration with warning (#685)
|
104
|
+
* Do not use :insecure option by default in Patron (#691)
|
105
|
+
* Fixes an issue with HTTPClient not raising a `Faraday::ConnectionFailed` (#702)
|
106
|
+
* Fixes YAML serialization/deserialization for `Faraday::Utils::Headers` (#690)
|
107
|
+
* Fixes an issue with Options having a nil value (#694)
|
108
|
+
* Fixes an issue with Faraday.default_connection not using Faraday.default_connection_options (#698)
|
109
|
+
* Fixes an issue with Options.merge! and Faraday instrumentation middleware (#710)
|
110
|
+
|
111
|
+
## v0.12.1
|
112
|
+
|
113
|
+
* Fix an issue with Patron tests failing on jruby
|
114
|
+
* Fix an issue with new `rewind_files` feature that was causing an exception when the body was not an Hash
|
115
|
+
* Expose wrapped_exception in all client errors
|
116
|
+
* Add Authentication Section to the ReadMe
|
117
|
+
|
118
|
+
## v0.12.0.1
|
119
|
+
|
120
|
+
* Hotfix release to address an issue with TravisCI deploy on Rubygems
|
121
|
+
|
122
|
+
## v0.12.0
|
123
|
+
|
124
|
+
Features:
|
125
|
+
|
126
|
+
* Proxy feature now relies on Ruby `URI::Generic#find_proxy` and can use `no_proxy` ENV variable (not compatible with ruby < 2.0)
|
127
|
+
* Adds support for `context` request option to pass arbitrary information to middlewares
|
128
|
+
|
129
|
+
Fixes:
|
130
|
+
|
131
|
+
* Fix an issue with options that was causing new options to override defaults ones unexpectedly
|
132
|
+
* Rewind `UploadIO`s on retry to fix a compatibility issue
|
133
|
+
* Make multipart boundary unique
|
134
|
+
* Improvements in `README.md`
|
135
|
+
|
136
|
+
## v0.11.0
|
137
|
+
|
138
|
+
Features:
|
139
|
+
|
140
|
+
* Add `filter` method to Logger middleware
|
141
|
+
* Add support for Ruby2.4 and Minitest 6
|
142
|
+
* Introduce block syntax to customise the adapter
|
143
|
+
|
144
|
+
Fixes:
|
145
|
+
|
146
|
+
* Fix an issue that was allowing to override `default_connection_options` from a connection instance
|
147
|
+
* Fix a bug that was causing newline escape characters ("\n") to be used when building the Authorization header
|
148
|
+
|
149
|
+
## v0.10.1
|
150
|
+
|
151
|
+
- Fix an issue with HTTPClient adapter that was causing the SSL to be reset on every request
|
152
|
+
- Rescue `IOError` instead of specific subclass
|
153
|
+
- `Faraday::Utils::Headers` can now be successfully serialised in YAML
|
154
|
+
- Handle `default_connection_options` set with hash
|
155
|
+
|
156
|
+
## v0.10.0
|
157
|
+
|
158
|
+
Breaking changes:
|
159
|
+
- Drop support for Ruby 1.8
|
160
|
+
|
161
|
+
Features:
|
162
|
+
- Include wrapped exception/reponse in ClientErrors
|
163
|
+
- Add `response.reason_phrase`
|
164
|
+
- Provide option to selectively skip logging request/response headers
|
165
|
+
- Add regex support for pattern matching in `test` adapter
|
166
|
+
|
167
|
+
Fixes:
|
168
|
+
- Add `Faraday.respond_to?` to find methods managed by `method_missing`
|
169
|
+
- em-http: `request.host` instead of `connection.host` should be taken for SSL validations
|
170
|
+
- Allow `default_connection_options` to be merged when options are passed as url parameter
|
171
|
+
- Improve splitting key-value pairs in raw HTTP headers
|
172
|
+
|
173
|
+
## v0.9.2
|
174
|
+
|
175
|
+
Adapters:
|
176
|
+
- Enable gzip compression for httpclient
|
177
|
+
- Fixes default certificate store for httpclient not having default paths.
|
178
|
+
- Make excon adapter compatible with 0.44 excon version
|
179
|
+
- Add compatibility with Patron 0.4.20
|
180
|
+
- Determine default port numbers in Net::HTTP adapters (Addressable compatibility)
|
181
|
+
- em-http: wrap "connection closed by server" as ConnectionFailed type
|
182
|
+
- Wrap Errno::ETIMEDOUT in Faraday::Error::TimeoutError
|
183
|
+
|
184
|
+
Utils:
|
185
|
+
- Add Rack-compatible support for parsing `a[][b]=c` nested queries
|
186
|
+
- Encode nil values in queries different than empty strings. Before: `a=`; now: `a`.
|
187
|
+
- Have `Faraday::Utils::Headers#replace` clear internal key cache
|
188
|
+
- Dup the internal key cache when a Headers hash is copied
|
189
|
+
|
190
|
+
Env and middleware:
|
191
|
+
- Ensure `env` stored on middleware response has reference to the response
|
192
|
+
- Ensure that Response properties are initialized during `on_complete` (VCR compatibility)
|
193
|
+
- Copy request options in Faraday::Connection#dup
|
194
|
+
- Env custom members should be copied by Env.from(env)
|
195
|
+
- Honour per-request `request.options.params_encoder`
|
196
|
+
- Fix `interval_randomness` data type for Retry middleware
|
197
|
+
- Add maximum interval option for Retry middleware
|
198
|
+
|
199
|
+
## v0.9.1
|
200
|
+
|
201
|
+
* Refactor Net:HTTP adapter so that with_net_http_connection can be overridden to allow pooled connections. (@Ben-M)
|
202
|
+
* Add configurable methods that bypass `retry_if` in the Retry request middleware. (@mike-bourgeous)
|
203
|
+
|
204
|
+
## v0.9.0
|
205
|
+
|
206
|
+
* Add HTTPClient adapter (@hakanensari)
|
207
|
+
* Improve Retry handler (@mislav)
|
208
|
+
* Remove autoloading by default (@technoweenie)
|
209
|
+
* Improve internal docs (@technoweenie, @mislav)
|
210
|
+
* Respect user/password in http proxy string (@mislav)
|
211
|
+
* Adapter options are structs. Reinforces consistent options across adapters
|
212
|
+
(@technoweenie)
|
213
|
+
* Stop stripping trailing / off base URLs in a Faraday::Connection. (@technoweenie)
|
214
|
+
* Add a configurable URI parser. (@technoweenie)
|
215
|
+
* Remove need to manually autoload when using the authorization header helpers on `Faraday::Connection`. (@technoweenie)
|
216
|
+
* `Faraday::Adapter::Test` respects the `Faraday::RequestOptions#params_encoder` option. (@technoweenie)
|
data/Rakefile
ADDED
data/lib/faraday.rb
CHANGED
@@ -124,9 +124,9 @@ module Faraday
|
|
124
124
|
end
|
125
125
|
rescue EventMachine::Connectify::CONNECTError => err
|
126
126
|
if err.message.include?("Proxy Authentication Required")
|
127
|
-
raise
|
127
|
+
raise Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
|
128
128
|
else
|
129
|
-
raise
|
129
|
+
raise Faraday::ConnectionFailed, err
|
130
130
|
end
|
131
131
|
rescue => err
|
132
132
|
if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
|
@@ -159,15 +159,15 @@ module Faraday
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def raise_error(msg)
|
162
|
-
errklass = Faraday::
|
162
|
+
errklass = Faraday::ClientError
|
163
163
|
if msg == Errno::ETIMEDOUT
|
164
|
-
errklass = Faraday::
|
164
|
+
errklass = Faraday::TimeoutError
|
165
165
|
msg = "request timed out"
|
166
166
|
elsif msg == Errno::ECONNREFUSED
|
167
|
-
errklass = Faraday::
|
167
|
+
errklass = Faraday::ConnectionFailed
|
168
168
|
msg = "connection refused"
|
169
169
|
elsif msg == "connection closed by server"
|
170
|
-
errklass = Faraday::
|
170
|
+
errklass = Faraday::ConnectionFailed
|
171
171
|
end
|
172
172
|
raise errklass, msg
|
173
173
|
end
|
@@ -193,11 +193,11 @@ module Faraday
|
|
193
193
|
|
194
194
|
def running?() @running end
|
195
195
|
|
196
|
-
def add
|
196
|
+
def add(&block)
|
197
197
|
if running?
|
198
198
|
perform_request { yield }
|
199
199
|
else
|
200
|
-
@registered_procs <<
|
200
|
+
@registered_procs << block
|
201
201
|
end
|
202
202
|
@num_registered += 1
|
203
203
|
end
|
@@ -211,7 +211,7 @@ module Faraday
|
|
211
211
|
end
|
212
212
|
end
|
213
213
|
if @errors.size > 0
|
214
|
-
raise Faraday::
|
214
|
+
raise Faraday::ClientError, @errors.first || "connection failed"
|
215
215
|
end
|
216
216
|
end
|
217
217
|
ensure
|
@@ -65,18 +65,18 @@ module Faraday
|
|
65
65
|
|
66
66
|
@app.call env
|
67
67
|
rescue Errno::ECONNREFUSED
|
68
|
-
raise
|
68
|
+
raise Faraday::ConnectionFailed, $!
|
69
69
|
rescue EventMachine::Connectify::CONNECTError => err
|
70
70
|
if err.message.include?("Proxy Authentication Required")
|
71
|
-
raise
|
71
|
+
raise Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
|
72
72
|
else
|
73
|
-
raise
|
73
|
+
raise Faraday::ConnectionFailed, err
|
74
74
|
end
|
75
75
|
rescue Errno::ETIMEDOUT => err
|
76
|
-
raise
|
76
|
+
raise Faraday::TimeoutError, err
|
77
77
|
rescue RuntimeError => err
|
78
78
|
if err.message == "connection closed by server"
|
79
|
-
raise
|
79
|
+
raise Faraday::ConnectionFailed, err
|
80
80
|
else
|
81
81
|
raise
|
82
82
|
end
|
@@ -59,14 +59,14 @@ module Faraday
|
|
59
59
|
@app.call env
|
60
60
|
rescue ::Excon::Errors::SocketError => err
|
61
61
|
if err.message =~ /\btimeout\b/
|
62
|
-
raise
|
62
|
+
raise Faraday::TimeoutError, err
|
63
63
|
elsif err.message =~ /\bcertificate\b/
|
64
64
|
raise Faraday::SSLError, err
|
65
65
|
else
|
66
|
-
raise
|
66
|
+
raise Faraday::ConnectionFailed, err
|
67
67
|
end
|
68
68
|
rescue ::Excon::Errors::Timeout => err
|
69
|
-
raise
|
69
|
+
raise Faraday::TimeoutError, err
|
70
70
|
end
|
71
71
|
|
72
72
|
def create_connection(env, opts)
|
@@ -43,15 +43,15 @@ module Faraday
|
|
43
43
|
|
44
44
|
@app.call env
|
45
45
|
rescue ::HTTPClient::TimeoutError, Errno::ETIMEDOUT
|
46
|
-
raise Faraday::
|
46
|
+
raise Faraday::TimeoutError, $!
|
47
47
|
rescue ::HTTPClient::BadResponseError => err
|
48
48
|
if err.message.include?('status 407')
|
49
|
-
raise Faraday::
|
49
|
+
raise Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
|
50
50
|
else
|
51
|
-
raise Faraday::
|
51
|
+
raise Faraday::ClientError, $!
|
52
52
|
end
|
53
53
|
rescue Errno::ECONNREFUSED, IOError, SocketError
|
54
|
-
raise Faraday::
|
54
|
+
raise Faraday::ConnectionFailed, $!
|
55
55
|
rescue => err
|
56
56
|
if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
|
57
57
|
raise Faraday::SSLError, err
|
@@ -45,7 +45,7 @@ module Faraday
|
|
45
45
|
if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
|
46
46
|
raise Faraday::SSLError, err
|
47
47
|
else
|
48
|
-
raise
|
48
|
+
raise Faraday::ConnectionFailed, err
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -58,7 +58,7 @@ module Faraday
|
|
58
58
|
|
59
59
|
@app.call env
|
60
60
|
rescue Timeout::Error, Errno::ETIMEDOUT => err
|
61
|
-
raise Faraday::
|
61
|
+
raise Faraday::TimeoutError, err
|
62
62
|
end
|
63
63
|
|
64
64
|
private
|
@@ -37,12 +37,12 @@ module Faraday
|
|
37
37
|
def perform_request(http, env)
|
38
38
|
http.request env[:url], create_request(env)
|
39
39
|
rescue Errno::ETIMEDOUT => error
|
40
|
-
raise Faraday::
|
40
|
+
raise Faraday::TimeoutError, error
|
41
41
|
rescue Net::HTTP::Persistent::Error => error
|
42
42
|
if error.message.include? 'Timeout'
|
43
|
-
raise Faraday::
|
43
|
+
raise Faraday::TimeoutError, error
|
44
44
|
elsif error.message.include? 'connection refused'
|
45
|
-
raise Faraday::
|
45
|
+
raise Faraday::ConnectionFailed, error
|
46
46
|
else
|
47
47
|
raise
|
48
48
|
end
|
@@ -28,7 +28,7 @@ module Faraday
|
|
28
28
|
data = env[:body] ? env[:body].to_s : nil
|
29
29
|
session.request(env[:method], env[:url].to_s, env[:request_headers], :data => data)
|
30
30
|
rescue Errno::ECONNREFUSED, ::Patron::ConnectionFailed
|
31
|
-
raise
|
31
|
+
raise Faraday::ConnectionFailed, $!
|
32
32
|
end
|
33
33
|
|
34
34
|
# Remove the "HTTP/1.1 200", leaving just the reason phrase
|
@@ -39,15 +39,15 @@ module Faraday
|
|
39
39
|
@app.call env
|
40
40
|
rescue ::Patron::TimeoutError => err
|
41
41
|
if connection_timed_out_message?(err.message)
|
42
|
-
raise Faraday::
|
42
|
+
raise Faraday::ConnectionFailed, err
|
43
43
|
else
|
44
|
-
raise Faraday::
|
44
|
+
raise Faraday::TimeoutError, err
|
45
45
|
end
|
46
46
|
rescue ::Patron::Error => err
|
47
47
|
if err.message.include?("code 407")
|
48
|
-
raise
|
48
|
+
raise Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
|
49
49
|
else
|
50
|
-
raise
|
50
|
+
raise Faraday::ConnectionFailed, err
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
data/lib/faraday/adapter/rack.rb
CHANGED
@@ -41,7 +41,7 @@ module Faraday
|
|
41
41
|
|
42
42
|
timeout = env[:request][:timeout] || env[:request][:open_timeout]
|
43
43
|
response = if timeout
|
44
|
-
Timer.timeout(timeout, Faraday::
|
44
|
+
Timer.timeout(timeout, Faraday::TimeoutError) { execute_request(env, rack_env) }
|
45
45
|
else
|
46
46
|
execute_request(env, rack_env)
|
47
47
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
# @param new_klass [Class] new Klass to use
|
5
|
+
#
|
6
|
+
# @return [Class] A modified version of new_klass that warns on
|
7
|
+
# usage about deprecation.
|
8
|
+
# @see Faraday::Deprecate
|
9
|
+
module DeprecatedClass
|
10
|
+
def self.proxy_class(origclass, ver = '1.0')
|
11
|
+
proxy = Class.new(origclass) do
|
12
|
+
class << self
|
13
|
+
extend Faraday::Deprecate
|
14
|
+
|
15
|
+
def ===(other)
|
16
|
+
other.is_a?(superclass) || super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
proxy.singleton_class.send(:deprecate, :new, "#{origclass}.new", ver)
|
21
|
+
proxy.singleton_class.send(:deprecate, :inherited, origclass.name, ver)
|
22
|
+
proxy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Deprecation using semver instead of date, based on Gem::Deprecate
|
27
|
+
# Provides a single method +deprecate+ to be used to declare when
|
28
|
+
# something is going away.
|
29
|
+
#
|
30
|
+
# class Legacy
|
31
|
+
# def self.klass_method
|
32
|
+
# # ...
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# def instance_method
|
36
|
+
# # ...
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# extend Faraday::Deprecate
|
40
|
+
# deprecate :instance_method, "X.z", '1.0'
|
41
|
+
#
|
42
|
+
# class << self
|
43
|
+
# extend Faraday::Deprecate
|
44
|
+
# deprecate :klass_method, :none, '1.0'
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
module Deprecate
|
48
|
+
def self.skip # :nodoc:
|
49
|
+
@skip ||= false
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.skip=(value) # :nodoc:
|
53
|
+
@skip = value
|
54
|
+
end
|
55
|
+
|
56
|
+
# Temporarily turn off warnings. Intended for tests only.
|
57
|
+
def skip_during
|
58
|
+
original = Faraday::Deprecate.skip
|
59
|
+
Faraday::Deprecate.skip, = true
|
60
|
+
yield
|
61
|
+
ensure
|
62
|
+
Faraday::Deprecate.skip = original
|
63
|
+
end
|
64
|
+
|
65
|
+
# Simple deprecation method that deprecates +name+ by wrapping it up
|
66
|
+
# in a dummy method. It warns on each call to the dummy method
|
67
|
+
# telling the user of +repl+ (unless +repl+ is :none) and the
|
68
|
+
# semver that it is planned to go away.
|
69
|
+
# @param name [Symbol] the method symbol to deprecate
|
70
|
+
# @param repl [#to_s, :none] the replacement to use, when `:none` it will
|
71
|
+
# alert the user that no replacemtent is present.
|
72
|
+
# @param ver [String] the semver the method will be removed.
|
73
|
+
def deprecate(name, repl, ver)
|
74
|
+
class_eval do
|
75
|
+
gem_ver = Gem::Version.new(ver)
|
76
|
+
old = "_deprecated_#{name}"
|
77
|
+
alias_method old, name
|
78
|
+
define_method name do |*args, &block|
|
79
|
+
mod = is_a? Module
|
80
|
+
target = mod ? "#{self}." : "#{self.class}#"
|
81
|
+
target_message = if name == :inherited
|
82
|
+
"Inheriting #{self}"
|
83
|
+
else
|
84
|
+
"#{target}#{name}"
|
85
|
+
end
|
86
|
+
|
87
|
+
msg = [
|
88
|
+
"NOTE: #{target_message} is deprecated",
|
89
|
+
repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
|
90
|
+
"It will be removed in or after version #{gem_ver}",
|
91
|
+
"\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
|
92
|
+
]
|
93
|
+
warn "#{msg.join}." unless Faraday::Deprecate.skip
|
94
|
+
send old, *args, &block
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
module_function :deprecate, :skip_during
|
100
|
+
end
|
101
|
+
end
|