rescue_from 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +9 -7
- data/lib/rescue_from/rescuable.rb +2 -2
- data/lib/rescue_from/version.rb +1 -1
- data/sig/lib/rescue_from/rescuable.rbs +7 -0
- metadata +3 -3
- data/sig/rescue_from.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14b3702a4648d12beaa0b3528ae7150d95163ecbcd855b65ee4a668438ac9768
|
4
|
+
data.tar.gz: e0c599ee47ea5696efb8df71a129e704b1352e884d4cb8b57db8955a2a8ac4c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adc7fa39ba5ecfd1044238eae23eebec329b98942a5e935f8a7f5db706acddf82b97badb8e5db764422ab4ecb69df6d16aed624c3cecfcca04c224236acf9ab8
|
7
|
+
data.tar.gz: 50e44c9bb18a21f3d4c31f8615716c70d42827bae11722373fe932996a0dc95ca89da0972f75d19ae503c09650377d952cc453f501e88e54a59c4ae11113c198
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,16 @@
|
|
8
8
|
### Bug fixes
|
9
9
|
)-->
|
10
10
|
|
11
|
+
## 2.0.0 2023-08-31
|
12
|
+
|
13
|
+
### Breaking changes
|
14
|
+
|
15
|
+
- Changed `self`-binding of exception handlers. Now handlers are executed in the same context as the method that raised the exception.
|
16
|
+
|
17
|
+
### New features
|
18
|
+
|
19
|
+
- Added RBS type signatures.
|
20
|
+
|
11
21
|
## 1.0.2 2023-08-30
|
12
22
|
|
13
23
|
### Bug fixes
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ An imitation of `ActiveSupport::Rescuable` that relies on Ruby's callbacks to re
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'rescue_from', '~>
|
10
|
+
gem 'rescue_from', '~> 2.0'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -29,15 +29,15 @@ Simply extend with `RescueFrom::Rescuable` any class or module that you want to
|
|
29
29
|
```ruby
|
30
30
|
class DataImporter
|
31
31
|
extend RescueFrom::Rescuable
|
32
|
-
|
32
|
+
|
33
33
|
rescue_from JSON::ParserError do
|
34
34
|
[]
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def temperature_data
|
38
38
|
JSON.parse File.read('temperatures.json')
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def humidity_data
|
42
42
|
JSON.parse File.read('humidity.json')
|
43
43
|
end
|
@@ -51,17 +51,19 @@ Both `#temperature_data` and `#humidity_data` will return an empty array if the
|
|
51
51
|
```ruby
|
52
52
|
class Service
|
53
53
|
extend RescueFrom::Rescuable
|
54
|
-
|
54
|
+
|
55
55
|
rescue_from(proc {|e| !e.message.start_with? 'failure'}) do
|
56
56
|
nil
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
...
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
63
63
|
If no pattern matches the exception, it will be reraised.
|
64
64
|
|
65
|
+
Handlers are called in the context of the receiver of the method that raised the exception.
|
66
|
+
|
65
67
|
If you want to call a given method bypassing the automatic exception handling, you can append `_without_rescue` to its name:
|
66
68
|
|
67
69
|
```ruby
|
@@ -105,7 +107,7 @@ If you want to limit automatic exception handling to only certain methods, you c
|
|
105
107
|
|
106
108
|
class Service
|
107
109
|
extend RescueFrom::Rescuable
|
108
|
-
|
110
|
+
|
109
111
|
ACTIONS = [:create, :update, :delete]
|
110
112
|
|
111
113
|
def self.should_rescue_in? method_name
|
@@ -29,7 +29,7 @@ module RescueFrom
|
|
29
29
|
|
30
30
|
def relabel *patterns, to:, &message_generator
|
31
31
|
rescue_from(*patterns) do |e|
|
32
|
-
raise to,
|
32
|
+
raise to, instance_exec(e, &message_generator)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -63,7 +63,7 @@ module RescueFrom
|
|
63
63
|
.filter_map { |ancestor_overrider| ancestor_overrider.handler_for e }
|
64
64
|
.first
|
65
65
|
.otherwise { raise e }
|
66
|
-
.therefore { |handler| handler
|
66
|
+
.therefore { |handler| instance_exec(e, &handler) }
|
67
67
|
end
|
68
68
|
# rubocop:enable Lint/RescueException
|
69
69
|
end
|
data/lib/rescue_from/version.rb
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
module RescueFrom
|
2
|
+
module Rescuable[T]
|
3
|
+
def rescue_from: (*Array::_Pattern[Exception] patterns) { () [self: T] -> untyped } -> void
|
4
|
+
def relabel: (*Array::_Pattern[Exception] patterns, to: Exception) { () [self: T] -> (String | untyped) } -> void
|
5
|
+
def should_rescue_in?: (Symbol method_name) -> bool
|
6
|
+
end
|
7
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rescue_from
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moku S.r.l.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-08-
|
12
|
+
date: 2023-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- lib/rescue_from/overrider.rb
|
59
59
|
- lib/rescue_from/rescuable.rb
|
60
60
|
- lib/rescue_from/version.rb
|
61
|
-
- sig/rescue_from.rbs
|
61
|
+
- sig/lib/rescue_from/rescuable.rbs
|
62
62
|
homepage: https://github.com/moku-io/rescue_from
|
63
63
|
licenses:
|
64
64
|
- MIT
|
data/sig/rescue_from.rbs
DELETED