trailblazer-circuit 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/Gemfile +1 -0
- data/lib/trailblazer/circuit/version.rb +1 -1
- data/lib/trailblazer/circuit.rb +1 -1
- data/lib/trailblazer/option.rb +79 -0
- metadata +3 -3
- data/lib/trailblazer/circuit/args.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51251c5182357e83918081e911da91c2ead537d0
|
4
|
+
data.tar.gz: 4f3087460b00f9e90b0d9584fde259d14cc20f2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef71bb646ac59d02d36a71644e7dd47cbbb91498495f03abe2a06853a0a4a050862fab8c985d2c0caeb0ae3e9aeab2dc1d5124731408d846b0bd769d8fffb650
|
7
|
+
data.tar.gz: dc0a566ee9e12352a7fa2c1accda1eb443967e10ab2f162752e8e15b223a1b7dd31f8d9f3b93c58f4178991c46f3e180a00c7d20098bb11638c1a45f11408ab1
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/lib/trailblazer/circuit.rb
CHANGED
@@ -120,7 +120,7 @@ end
|
|
120
120
|
|
121
121
|
require "trailblazer/circuit/activity"
|
122
122
|
require "trailblazer/circuit/task"
|
123
|
-
require "trailblazer/
|
123
|
+
require "trailblazer/option"
|
124
124
|
require "trailblazer/circuit/alter"
|
125
125
|
require "trailblazer/circuit/trace"
|
126
126
|
require "trailblazer/circuit/present"
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# TODO: test all this, for christ's sake.
|
2
|
+
|
3
|
+
module Trailblazer
|
4
|
+
# @note This might go to trailblazer-args along with `Context` at some point.
|
5
|
+
def self.Option(proc)
|
6
|
+
Option.build(Option, proc)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Option
|
10
|
+
# Generic builder for a callable "option".
|
11
|
+
# @param call_implementation [Class, Module] implements the process of calling the proc
|
12
|
+
# while passing arguments/options to it in a specific style (e.g. kw args, step interface).
|
13
|
+
# @return [Proc] when called, this proc will evaluate its option (at run-time).
|
14
|
+
def self.build(call_implementation, proc)
|
15
|
+
if proc.is_a? Symbol
|
16
|
+
->(*args) { call_implementation.evaluate_method(proc, *args) }
|
17
|
+
else
|
18
|
+
->(*args) { call_implementation.evaluate_callable(proc, *args) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# A call implementation invoking `proc.(*args)` and plainly forwarding all arguments.
|
23
|
+
# Override this for your own step strategy (see KW#call!).
|
24
|
+
# @private
|
25
|
+
def self.call!(proc, *args)
|
26
|
+
proc.(*args)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Note that both #evaluate_callable and #evaluate_method drop most of the args.
|
30
|
+
# If you need those, override this class.
|
31
|
+
# @private
|
32
|
+
def self.evaluate_callable(proc, *args)
|
33
|
+
call!(proc, *args)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Make the context's instance method a "lambda" and reuse #call!.
|
37
|
+
# @private
|
38
|
+
def self.evaluate_method(proc, *args, exec_context:raise, **flow_options)
|
39
|
+
call!(exec_context.method(proc), *args)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns a {Proc} that, when called, invokes the `proc` argument with keyword arguments.
|
43
|
+
# This is known as "step (call) interface".
|
44
|
+
#
|
45
|
+
# This is commonly used by `Operation::step` to wrap the argument and make it
|
46
|
+
# callable in the circuit.
|
47
|
+
#
|
48
|
+
# my_proc = ->(options, **kws) { options["i got called"] = true }
|
49
|
+
# task = Trailblazer::Option::KW(my_proc)
|
50
|
+
# task.(options = {})
|
51
|
+
# options["i got called"] #=> true
|
52
|
+
#
|
53
|
+
# Alternatively, you can pass a symbol and an `:exec_context`.
|
54
|
+
#
|
55
|
+
# my_proc = :some_method
|
56
|
+
# task = Trailblazer::Option::KW(my_proc)
|
57
|
+
#
|
58
|
+
# class A
|
59
|
+
# def some_method(options, **kws)
|
60
|
+
# options["i got called"] = true
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# task.(options = {}, exec_context: A.new)
|
65
|
+
# options["i got called"] #=> true
|
66
|
+
def self.KW(proc)
|
67
|
+
Option.build(KW, proc)
|
68
|
+
end
|
69
|
+
|
70
|
+
class KW < Option
|
71
|
+
# A different call implementation that calls `proc` with a "step interface".
|
72
|
+
# your_code.(options, **options)
|
73
|
+
# @private
|
74
|
+
def self.call!(proc, options, *)
|
75
|
+
proc.(options, **options.to_hash) # Step interface: (options, **)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-circuit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,7 +98,6 @@ files:
|
|
98
98
|
- lib/trailblazer/circuit.rb
|
99
99
|
- lib/trailblazer/circuit/activity.rb
|
100
100
|
- lib/trailblazer/circuit/alter.rb
|
101
|
-
- lib/trailblazer/circuit/args.rb
|
102
101
|
- lib/trailblazer/circuit/present.rb
|
103
102
|
- lib/trailblazer/circuit/task.rb
|
104
103
|
- lib/trailblazer/circuit/testing.rb
|
@@ -106,6 +105,7 @@ files:
|
|
106
105
|
- lib/trailblazer/circuit/version.rb
|
107
106
|
- lib/trailblazer/circuit/wrap.rb
|
108
107
|
- lib/trailblazer/context.rb
|
108
|
+
- lib/trailblazer/option.rb
|
109
109
|
- trailblazer-circuit.gemspec
|
110
110
|
homepage: http://trailblazer.to/gems/workflow
|
111
111
|
licenses: []
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module Trailblazer
|
2
|
-
# @note This might go to trailblazer-args along with `Context` at some point.
|
3
|
-
class Args
|
4
|
-
class << self
|
5
|
-
# Returns a {Proc} that, when called, invokes the `proc` argument with keyword arguments.
|
6
|
-
# This is known as "step (call) interface".
|
7
|
-
#
|
8
|
-
# This is commonly used by `Operation::step` to wrap the argument and make it
|
9
|
-
# callable in the circuit.
|
10
|
-
#
|
11
|
-
# my_proc = ->(options, **kws) { options["i got called"] = true }
|
12
|
-
# task = Trailblazer::Args::KW(my_proc)
|
13
|
-
# task.(options = {})
|
14
|
-
# options["i got called"] #=> true
|
15
|
-
#
|
16
|
-
# Alternatively, you can pass a symbol and an `:exec_context`.
|
17
|
-
#
|
18
|
-
# my_proc = :some_method
|
19
|
-
# task = Trailblazer::Args::KW(my_proc)
|
20
|
-
#
|
21
|
-
# class A
|
22
|
-
# def some_method(options, **kws)
|
23
|
-
# options["i got called"] = true
|
24
|
-
# end
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# task.(options = {}, exec_context: A.new)
|
28
|
-
# options["i got called"] #=> true
|
29
|
-
def KW(proc)
|
30
|
-
if proc.is_a? Symbol
|
31
|
-
->(*args) { call_method!(proc, *args) }
|
32
|
-
else
|
33
|
-
->(*args) { call_callable!(proc, *args) }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
# Calls `proc` with a "step" interface.
|
40
|
-
# Override this for your own step strategy.
|
41
|
-
def call!(proc, options)
|
42
|
-
proc.(options, **options.to_hash) # Step interface: (options, **)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Note that both #call_callable! and #call_method! drop most of the args.
|
46
|
-
# If you need those, override this class.
|
47
|
-
def call_callable!(proc, options, *)
|
48
|
-
call!(proc, options)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Make the context's instance method a "lambda" and reuse #call!.
|
52
|
-
def call_method!(proc, options, exec_context:raise, **)
|
53
|
-
call!(exec_context.method(proc), options)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|