rescue_from 1.0.2 → 2.0.1
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 +16 -0
- data/README.md +9 -7
- data/lib/rescue_from/rescuable.rb +14 -3
- data/lib/rescue_from/version.rb +1 -1
- data/lib/rescue_from.rb +1 -1
- data/rescue_from.gemspec +33 -0
- data/sig/lib/rescue_from/rescuable.rbs +7 -0
- metadata +9 -8
- 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: 1e7cf4a9bf36425ce3acf49eb954ebcc4c54b2a4a0cec6b5fbce7431becf1217
|
4
|
+
data.tar.gz: 9b532f17f235307cb4fab085e33a03e4faa0484acb6d1d56057e93d177f05b8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a13694ba98c354c60c14e1a2d52aaf3ca72cbf3ab35920b59d5b9bbb91052bcbaea22e41931f492131965b16471604bacdc8677b662e8d9bd2148461c431396b
|
7
|
+
data.tar.gz: 318c354c114a880558120dc648568c6508c02ebea4933f06f287de59a5fc325e6f1534b9362dbd0138b1dcc0947afdc07e70040a1fc1b9df88d94ce3c8bb4b1b
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,22 @@
|
|
8
8
|
### Bug fixes
|
9
9
|
)-->
|
10
10
|
|
11
|
+
## 2.0.1 2025-01-20
|
12
|
+
|
13
|
+
### Bug fixes
|
14
|
+
|
15
|
+
- Relaxed dependency.
|
16
|
+
|
17
|
+
## 2.0.0 2023-08-31
|
18
|
+
|
19
|
+
### Breaking changes
|
20
|
+
|
21
|
+
- Changed `self`-binding of exception handlers. Now handlers are executed in the same context as the method that raised the exception.
|
22
|
+
|
23
|
+
### New features
|
24
|
+
|
25
|
+
- Added RBS type signatures.
|
26
|
+
|
11
27
|
## 1.0.2 2023-08-30
|
12
28
|
|
13
29
|
### 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
|
|
@@ -47,8 +47,9 @@ module RescueFrom
|
|
47
47
|
return if overrider.method_defined? name
|
48
48
|
|
49
49
|
method_without_rescue = instance_method name
|
50
|
+
name_without_rescue = :"#{name}_without_rescue"
|
50
51
|
|
51
|
-
overrider.define_method
|
52
|
+
overrider.define_method name_without_rescue do |*args, **kwargs, &block|
|
52
53
|
method_without_rescue.bind_call(self, *args, **kwargs, &block)
|
53
54
|
end
|
54
55
|
|
@@ -63,9 +64,19 @@ module RescueFrom
|
|
63
64
|
.filter_map { |ancestor_overrider| ancestor_overrider.handler_for e }
|
64
65
|
.first
|
65
66
|
.otherwise { raise e }
|
66
|
-
.therefore { |handler| handler
|
67
|
+
.therefore { |handler| instance_exec(e, name, &handler) }
|
67
68
|
end
|
68
69
|
# rubocop:enable Lint/RescueException
|
70
|
+
|
71
|
+
if private_method_defined? name
|
72
|
+
overrider.class_exec do
|
73
|
+
private name, name_without_rescue
|
74
|
+
end
|
75
|
+
elsif protected_method_defined? name
|
76
|
+
overrider.class_exec do
|
77
|
+
protected name, name_without_rescue
|
78
|
+
end
|
79
|
+
end
|
69
80
|
end
|
70
81
|
end
|
71
82
|
end
|
data/lib/rescue_from/version.rb
CHANGED
data/lib/rescue_from.rb
CHANGED
data/rescue_from.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'lib/rescue_from/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'rescue_from'
|
5
|
+
spec.version = RescueFrom::VERSION
|
6
|
+
spec.authors = ['Moku S.r.l.', 'Riccardo Agatea']
|
7
|
+
spec.email = ['info@moku.io']
|
8
|
+
spec.license = 'MIT'
|
9
|
+
|
10
|
+
spec.summary = 'An imitation of ActiveSupport::Rescuable that relies on Ruby\'s callbacks to reduce boilerplate code.'
|
11
|
+
spec.description = 'An imitation of ActiveSupport::Rescuable that relies on Ruby\'s callbacks to reduce ' \
|
12
|
+
'boilerplate code.'
|
13
|
+
spec.homepage = 'https://github.com/moku-io/rescue_from'
|
14
|
+
spec.required_ruby_version = '>= 2.6.0'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/moku-io/rescue_from'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/moku-io/rescue_from/blob/master/CHANGELOG.md'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir __dir__ do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_dependency 'activesupport'
|
32
|
+
spec.add_dependency 'therefore', '~> 1.0'
|
33
|
+
end
|
@@ -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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moku S.r.l.
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: therefore
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,8 @@ files:
|
|
58
58
|
- lib/rescue_from/overrider.rb
|
59
59
|
- lib/rescue_from/rescuable.rb
|
60
60
|
- lib/rescue_from/version.rb
|
61
|
-
-
|
61
|
+
- rescue_from.gemspec
|
62
|
+
- sig/lib/rescue_from/rescuable.rbs
|
62
63
|
homepage: https://github.com/moku-io/rescue_from
|
63
64
|
licenses:
|
64
65
|
- MIT
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.5.22
|
85
86
|
signing_key:
|
86
87
|
specification_version: 4
|
87
88
|
summary: An imitation of ActiveSupport::Rescuable that relies on Ruby's callbacks
|
data/sig/rescue_from.rbs
DELETED