rescue_from 1.0.1 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d977c0f9b3724de3252639910ef681161908d17770a5a0a73d470e0ebbe57be
4
- data.tar.gz: 9a8a6321b8ab19a0e54791d7b8c1a7042f2c9edd9b7268b6911a476b84d0955d
3
+ metadata.gz: 14b3702a4648d12beaa0b3528ae7150d95163ecbcd855b65ee4a668438ac9768
4
+ data.tar.gz: e0c599ee47ea5696efb8df71a129e704b1352e884d4cb8b57db8955a2a8ac4c5
5
5
  SHA512:
6
- metadata.gz: d87c764a8e4a9e062d0d06c1b76f944d1d02e2a29f4679cff830c5169c9bac983cec85431453e6e5f42e79e2587a553e9ffd0cdb4cb6bb242160519ce8752d82
7
- data.tar.gz: 8be62529ff4974790dd80d3ab4b65f5a4da834960a84e97cdb8a121443a9656796cca5d9a7719a7958b3737059db83bd054ab124abbcd3b00ac9c402ad870451
6
+ metadata.gz: adc7fa39ba5ecfd1044238eae23eebec329b98942a5e935f8a7f5db706acddf82b97badb8e5db764422ab4ecb69df6d16aed624c3cecfcca04c224236acf9ab8
7
+ data.tar.gz: 50e44c9bb18a21f3d4c31f8615716c70d42827bae11722373fe932996a0dc95ca89da0972f75d19ae503c09650377d952cc453f501e88e54a59c4ae11113c198
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ <!--[//]: # (
4
+ ## <Release number> <Date YYYY-MM-DD>
5
+ ### Breaking changes
6
+ ### Deprecations
7
+ ### New features
8
+ ### Bug fixes
9
+ )-->
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
+
21
+ ## 1.0.2 2023-08-30
22
+
23
+ ### Bug fixes
24
+
25
+ - Removed the `Error` class.
26
+
3
27
  ## 1.0.1 2023-06-07
4
28
 
5
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', '~> 1.0'
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, message_generator.call(e)
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.call e }
66
+ .therefore { |handler| instance_exec(e, &handler) }
67
67
  end
68
68
  # rubocop:enable Lint/RescueException
69
69
  end
@@ -1,3 +1,3 @@
1
1
  module RescueFrom
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
data/lib/rescue_from.rb CHANGED
@@ -1,8 +1,3 @@
1
1
  require 'therefore'
2
2
  require_relative "rescue_from/version"
3
-
4
- module RescueFrom
5
- class Error < StandardError; end
6
- end
7
-
8
3
  require_relative 'rescue_from/rescuable'
@@ -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: 1.0.1
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-06-07 00:00:00.000000000 Z
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
@@ -1,4 +0,0 @@
1
- module RescueFrom
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end