direct 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/direct.rb +2 -2
- data/lib/direct/executable.rb +32 -7
- data/lib/direct/strict_executable.rb +32 -5
- data/lib/direct/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20440d5b3580056507598e8506d9a6e8e26623601dc07ed6cfc443ee2e4dee04
|
4
|
+
data.tar.gz: 981844bd5ede5b4b889ed19ee5ca16cc2c6cdcaa898f166bc3e3132d8034e962
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7207fd5bd4c1447f4686deff93bddd8d9802722accaa37118979afd0fc46afe75f616a73ffa24628ccfb111c3121ff92319346484c914931f753cce4102059f
|
7
|
+
data.tar.gz: 628cd5d0416be38cdfe79a7a50473c0b59944af35d3b6c01264562dfc0d7f11287d13908ef1c63d9ddc30f870aefdf1a8327c38765c3e246aea7db9d8c28aa8c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## Version 1.2.1
|
2
|
+
|
3
|
+
Provide an 'object:' to a Direct.defer or Direct.strict_defer to be sent as the third parameter in the executed blocks.
|
4
|
+
|
1
5
|
## Version 1.2.0
|
2
6
|
|
3
7
|
Provide a Direct.defer and Direct.strict_defer to allow deferring blocks without success and failure procedures.
|
data/lib/direct.rb
CHANGED
data/lib/direct/executable.rb
CHANGED
@@ -16,11 +16,36 @@ module Direct
|
|
16
16
|
#
|
17
17
|
# Direct.defer(->{ "call me, maybe" })
|
18
18
|
#
|
19
|
-
|
19
|
+
# You may also provide an 'object:' parameter which will be
|
20
|
+
# passed to the provided blocks when they are ultimately executed
|
21
|
+
#
|
22
|
+
# Example:
|
23
|
+
#
|
24
|
+
# Direct.defer(object: self) do
|
25
|
+
# # do work here
|
26
|
+
# end.success {|deferred, deferred_block_result, object|
|
27
|
+
# # you have access to the provided object here
|
28
|
+
# }
|
29
|
+
#
|
30
|
+
# The object is a useful reference because the Executable instance
|
31
|
+
# is the deferred object, instead of the object using Direct.defer
|
32
|
+
#
|
33
|
+
# class Thing
|
34
|
+
# def do_something
|
35
|
+
# Direct.defer(object: self){ do_the_work }
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# Thing.new.do_something.success {|deferred, result, thing|
|
40
|
+
# puts "The #{thing} did something!"
|
41
|
+
# }.execute
|
42
|
+
#
|
43
|
+
def initialize(callable=nil, object: nil, &block)
|
44
|
+
@object = object
|
20
45
|
@execution = callable || block
|
21
46
|
@exception_classes = [StandardError]
|
22
47
|
end
|
23
|
-
attr_reader :execution, :exception_classes
|
48
|
+
attr_reader :execution, :exception_classes, :object
|
24
49
|
|
25
50
|
# Tell the object what to do for a success path
|
26
51
|
#
|
@@ -51,7 +76,7 @@ module Direct
|
|
51
76
|
#
|
52
77
|
# Direct.defer {
|
53
78
|
# # something...
|
54
|
-
# }.exception(NoMethodError) { |deferred, exception|
|
79
|
+
# }.exception(NoMethodError) { |deferred, exception, object|
|
55
80
|
# ExceptionNotifier.notify(exception)
|
56
81
|
# }
|
57
82
|
#
|
@@ -65,9 +90,9 @@ module Direct
|
|
65
90
|
|
66
91
|
def run_exception_block(exception)
|
67
92
|
if __directions.key?(:exception)
|
68
|
-
as_directed(:exception, exception)
|
93
|
+
as_directed(:exception, exception, object)
|
69
94
|
else
|
70
|
-
as_directed(:failure, exception)
|
95
|
+
as_directed(:failure, exception, object)
|
71
96
|
end
|
72
97
|
end
|
73
98
|
private :run_exception_block
|
@@ -79,9 +104,9 @@ module Direct
|
|
79
104
|
def value
|
80
105
|
result = execution.()
|
81
106
|
if result
|
82
|
-
as_directed(:success, result)
|
107
|
+
as_directed(:success, result, object)
|
83
108
|
else
|
84
|
-
as_directed(:failure, result)
|
109
|
+
as_directed(:failure, result, object)
|
85
110
|
end
|
86
111
|
rescue *exception_classes => exception
|
87
112
|
run_exception_block(exception)
|
@@ -16,11 +16,38 @@ module Direct
|
|
16
16
|
#
|
17
17
|
# Direct.strict_defer(->{ "call me, maybe" })
|
18
18
|
#
|
19
|
-
|
19
|
+
# You may also provide an 'object:' parameter which will be
|
20
|
+
# passed to the provided blocks when they are ultimately executed
|
21
|
+
#
|
22
|
+
# Example:
|
23
|
+
#
|
24
|
+
# Direct.strict_defer(object: self) do
|
25
|
+
# # do work here
|
26
|
+
# end.success {|deferred, deferred_block_result, object|
|
27
|
+
# # you have access to the provided object here
|
28
|
+
# }
|
29
|
+
#
|
30
|
+
# The object is a useful reference because the Executable instance
|
31
|
+
# is the deferred object, instead of the object using Direct.strict_defer
|
32
|
+
#
|
33
|
+
# class Thing
|
34
|
+
# def do_something
|
35
|
+
# Direct.strict_defer(object: self){ do_the_work }
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# Thing.new.do_something.success {|deferred, result, thing|
|
40
|
+
# puts "The #{thing} did something!"
|
41
|
+
# }.failure{|_,_,thing|
|
42
|
+
# puts "#{thing} failed!"
|
43
|
+
# }.execute
|
44
|
+
#
|
45
|
+
def initialize(callable=nil, object: nil, &block)
|
46
|
+
@object = object
|
20
47
|
@execution = callable || block
|
21
48
|
@exception_classes = [StandardError]
|
22
49
|
end
|
23
|
-
attr_reader :execution, :exception_classes
|
50
|
+
attr_reader :execution, :exception_classes, :object
|
24
51
|
|
25
52
|
# Tell the object what to do for a success path
|
26
53
|
#
|
@@ -51,7 +78,7 @@ module Direct
|
|
51
78
|
#
|
52
79
|
# Direct.strict_defer {
|
53
80
|
# # something...
|
54
|
-
# }.exception(NoMethodError) { |deferred, exception|
|
81
|
+
# }.exception(NoMethodError) { |deferred, exception, object|
|
55
82
|
# ExceptionNotifier.notify(exception)
|
56
83
|
# }
|
57
84
|
#
|
@@ -65,9 +92,9 @@ module Direct
|
|
65
92
|
|
66
93
|
def run_exception_block(exception)
|
67
94
|
if __directions.key?(:exception)
|
68
|
-
as_directed(:exception, exception)
|
95
|
+
as_directed(:exception, exception, object)
|
69
96
|
else
|
70
|
-
as_directed(:failure, exception)
|
97
|
+
as_directed(:failure, exception, object)
|
71
98
|
end
|
72
99
|
end
|
73
100
|
private :run_exception_block
|
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: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Gay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|