fetch 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +10 -3
- data/lib/fetch/base.rb +1 -2
- data/lib/fetch/version.rb +1 -1
- data/test/error_test.rb +6 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a10520fb3d8cc9508aef80fe19c88dd4b5b72a71
|
4
|
+
data.tar.gz: cc19fba644b2236f5833f312bf002b495258caf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b23e3bb9c6e49e85d07e37791d46343d5f36467dc279498a9da855ff8580ce3e0df3515bbf58b17222b7b013ee1be5619ec6af746fc7607c573ced140abc07b
|
7
|
+
data.tar.gz: 3239bdfb8eb3ce1855efcad29227fa59ff0c23893781da47b85cae867440edc1e99d35188777e482b3764ec5853b81313b0d604a61e0324d0dae52dc2b192111
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -225,20 +225,27 @@ whole fetch to fail. So please add error handling :blush:
|
|
225
225
|
|
226
226
|
### General error handling
|
227
227
|
|
228
|
-
|
229
|
-
|
230
|
-
in your fetcher callbacks.
|
228
|
+
If you need to ensure that something is run, even if anything in the fetch
|
229
|
+
fails, you can add an `error` callback to your `Fetch::Base` subclass.
|
231
230
|
|
232
231
|
```ruby
|
233
232
|
class UserFetcher < Fetch::Base
|
234
233
|
modules Facebook::UserInfoFetch,
|
235
234
|
Github::UserInfoFetch
|
236
235
|
|
236
|
+
before_fetch do
|
237
|
+
this_fails!
|
238
|
+
end
|
239
|
+
|
237
240
|
error do |e|
|
238
241
|
# Do something that must be done,
|
239
242
|
# even if the fetch fails.
|
240
243
|
end
|
241
244
|
end
|
245
|
+
|
246
|
+
user = User.find(123)
|
247
|
+
UserFetcher.new(user).fetch
|
248
|
+
# => raises an exception, but the error callback will be run before that.
|
242
249
|
```
|
243
250
|
|
244
251
|
### Parsing JSON
|
data/lib/fetch/base.rb
CHANGED
data/lib/fetch/version.rb
CHANGED
data/test/error_test.rb
CHANGED
@@ -17,23 +17,10 @@ class ErrorTest < Minitest::Test
|
|
17
17
|
actions << "got #{e.message}"
|
18
18
|
end
|
19
19
|
end
|
20
|
-
klass.new.fetch
|
21
|
-
assert_match /got undefined method `this_wont_work!'/, actions.first
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_exception_is_raised_if_no_error_callback_specified
|
25
|
-
stub_request(:get, "http://test.com/one").to_return(body: "got one")
|
26
|
-
mod = Class.new(Fetch::Module) do
|
27
|
-
request do |req|
|
28
|
-
req.url = "http://test.com/one"
|
29
|
-
req.process do |body|
|
30
|
-
this_wont_work!
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
20
|
assert_raises NoMethodError do
|
35
|
-
|
21
|
+
klass.new.fetch
|
36
22
|
end
|
23
|
+
assert_match /got undefined method `this_wont_work!'/, actions.first
|
37
24
|
end
|
38
25
|
|
39
26
|
[:modules, :load, :init, :before_fetch, :after_fetch, :progress].each do |callback|
|
@@ -54,7 +41,9 @@ class ErrorTest < Minitest::Test
|
|
54
41
|
actions << "got #{e.message}"
|
55
42
|
end
|
56
43
|
end
|
57
|
-
|
44
|
+
assert_raises NoMethodError do
|
45
|
+
klass.new.fetch
|
46
|
+
end
|
58
47
|
assert_match /got undefined method `this_#{callback}_fails!'/, actions.first
|
59
48
|
end
|
60
49
|
end
|
@@ -68,9 +57,7 @@ class ErrorTest < Minitest::Test
|
|
68
57
|
req.process do |body|
|
69
58
|
this_wont_work!
|
70
59
|
end
|
71
|
-
|
72
|
-
|
73
|
-
error do |e|
|
60
|
+
req.error {}
|
74
61
|
end
|
75
62
|
end
|
76
63
|
klass = Class.new(MockFetcher(mod)) do
|