direct 2.0.1 → 2.1.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 +3 -0
- data/README.md +28 -0
- data/lib/direct/exception_handler.rb +6 -1
- data/lib/direct/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b89861d3e32e540516068bfc32e68400da28980ab260a14c9d0225b4cf12f78
|
4
|
+
data.tar.gz: 2a9134c83f29c6409bbf00c1d57272fbc6f1a5a907a1501cb903abd1fc8cd4c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ff7abfcc77044b071373176421637e193400b1e019a2a9be3689ceff5326d862d9a9f005a28f80a45d83102b96e6252532e504e11ae731ff44df65e60edcba5
|
7
|
+
data.tar.gz: 45418478b7ac061e2d41a2b066230673300d840ee70f7cee928fa282f5d44c2fca0784302d33df6d752f21a3dd639330e564e3048626d5785280b23e40987352
|
data/CHANGELOG.md
CHANGED
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
|
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
|
data/lib/direct/version.rb
CHANGED
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
|
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:
|
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.
|
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: []
|