fetch 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f7ab6433f70dc724bd8e7640a072ee3ca26555c
4
- data.tar.gz: f25919595f00945f1bb6b1b41e40ca1940ac2421
3
+ metadata.gz: a10520fb3d8cc9508aef80fe19c88dd4b5b72a71
4
+ data.tar.gz: cc19fba644b2236f5833f312bf002b495258caf7
5
5
  SHA512:
6
- metadata.gz: cf303622302ebf70d0f071fc14d99f55dc8b748aae0789397c4afc09c76c1eb5a1c2c60332d28e742f6f9c504ff240d79415dc7122432c3f11d70b4497653e06
7
- data.tar.gz: 41b866ef62c1d97f23b2f634b384898023aee0ee61f3caac231d4d11971e34b91b558b812bdf5564018a5dc7b8df75e4a2ab74cd741fc1a8701e9e34a1164c64
6
+ metadata.gz: 4b23e3bb9c6e49e85d07e37791d46343d5f36467dc279498a9da855ff8580ce3e0df3515bbf58b17222b7b013ee1be5619ec6af746fc7607c573ced140abc07b
7
+ data.tar.gz: 3239bdfb8eb3ce1855efcad29227fa59ff0c23893781da47b85cae867440edc1e99d35188777e482b3764ec5853b81313b0d604a61e0324d0dae52dc2b192111
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.0.4
4
+
5
+ * Exceptions are raised after the general `Fetch::Base` `error` callback is
6
+ run.
7
+
3
8
  ## Version 0.0.3
4
9
 
5
10
  * Adds an general `error` callback to `Fetch::Base` for catching any unhandled
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
- You add a "catch all" `error` callback to your fetcher subclassed from
229
- `Fetch::Base`. This enables you to handle any unhandled errors, including errors
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
@@ -47,9 +47,8 @@ module Fetch
47
47
 
48
48
  true
49
49
  rescue => e
50
- raise e unless callback?(:error)
51
50
  error(e)
52
- false
51
+ raise e
53
52
  end
54
53
 
55
54
  private
@@ -1,3 +1,3 @@
1
1
  module Fetch
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
- MockFetcher(mod).new.fetch
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
- klass.new.fetch
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
- end
72
-
73
- error do |e|
60
+ req.error {}
74
61
  end
75
62
  end
76
63
  klass = Class.new(MockFetcher(mod)) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Bunk