direct 2.0.1 → 2.1.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: 0c4b78452caed73b8ce6c197b9825690120664cfedf0a695e0b8dee7d3f93e9e
4
- data.tar.gz: d16639349d3041cc46fd0aa8edf6cc6565e24ff70b97dd275bc6c4dbeba1c853
3
+ metadata.gz: 4b89861d3e32e540516068bfc32e68400da28980ab260a14c9d0225b4cf12f78
4
+ data.tar.gz: 2a9134c83f29c6409bbf00c1d57272fbc6f1a5a907a1501cb903abd1fc8cd4c9
5
5
  SHA512:
6
- metadata.gz: 2193d4a0199deb76f94bdcb22fe6042d393a32a0a23581f6957f066d6609ad51e8590436a284fa818a939b3fcd00aa495724d229d9af65c18e9dd86bc0e670ff
7
- data.tar.gz: cd31472b4a110ceeab0cff5af7700314b71e10f911b12a426491acc94019879d92374cefdc301cc258cf3c5197f097bc9d32ae8e5209569dd7102f26131a6fe8
6
+ metadata.gz: 5ff7abfcc77044b071373176421637e193400b1e019a2a9be3689ceff5326d862d9a9f005a28f80a45d83102b96e6252532e504e11ae731ff44df65e60edcba5
7
+ data.tar.gz: 45418478b7ac061e2d41a2b066230673300d840ee70f7cee928fa282f5d44c2fca0784302d33df6d752f21a3dd639330e564e3048626d5785280b23e40987352
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## Version 2.1.0
2
+
3
+ Check for inheritance on exception handler exceptions.
1
4
  ## Version 2.0.1
2
5
 
3
6
  Introduce an ExceptionHandler to allow for multiple exception blocks
data/README.md CHANGED
@@ -84,6 +84,34 @@ DeferrableClass.new.direct(:success){|instance, *data|
84
84
 
85
85
  Your blocks will always receive the object itself as the first argument.
86
86
 
87
+ If you want to have a better API, just make it your own:
88
+
89
+ ```ruby
90
+ class DeferrableClass
91
+ def when_it_works(&)
92
+ direct(:success, &)
93
+ end
94
+
95
+ def when_it_fails(&)
96
+ direct(:oopsies, &)
97
+ end
98
+
99
+ def do_it
100
+ if it_worked?
101
+ as_directed(:success)
102
+ else
103
+ as_directed(:oopsies)
104
+ end
105
+ end
106
+ end
107
+
108
+ DeferrableClass.new.when_it_works do |instance|
109
+ # successful path
110
+ end.when_it_fails do |instance|
111
+ # failure path
112
+ end
113
+ ```
114
+
87
115
  ## Why?
88
116
 
89
117
  You could easily write code that says `if` this `else` that.
@@ -23,7 +23,12 @@ module Direct
23
23
  # deferred object.
24
24
  def call(deferred, exception, object)
25
25
  if_none = proc { raise "No handler for this exception: #{exception.class}!" }
26
- result = @handlers.find(if_none) { |key, val| key.include?(exception.class) }
26
+ result = @handlers.find { |key, val| key.include?(exception.class) }
27
+ if result.nil?
28
+ result = @handlers.find(if_none) do |key, val|
29
+ key.find { |klass| exception.class < klass }
30
+ end
31
+ end
27
32
 
28
33
  result.last.call(deferred, exception, object)
29
34
  end
@@ -1,3 +1,3 @@
1
1
  module Direct
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-28 00:00:00.000000000 Z
11
+ date: 2023-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -46,7 +46,7 @@ homepage: https://github.com/saturnflyer/direct
46
46
  licenses:
47
47
  - MIT
48
48
  metadata: {}
49
- post_install_message:
49
+ post_install_message:
50
50
  rdoc_options: []
51
51
  require_paths:
52
52
  - lib
@@ -61,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.4.1
65
- signing_key:
64
+ rubygems_version: 3.4.10
65
+ signing_key:
66
66
  specification_version: 4
67
67
  summary: Direct objects to perform arbitrary blocks by name
68
68
  test_files: []