trailblazer-circuit 0.0.6 → 0.0.7
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/lib/trailblazer/circuit.rb +1 -0
- data/lib/trailblazer/circuit/args.rb +57 -0
- data/lib/trailblazer/circuit/task.rb +1 -30
- data/lib/trailblazer/circuit/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b52e8d764a309e9a8977564a19ddf387c236aea0
|
4
|
+
data.tar.gz: ae086ee946f06831f4f513bbaae68292864787c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e76bc0e1ce8ea6a5a14563826947b81ea3223b2cbc8aee0b1f9fd1d54d7414fd43f1f8a8a071500fb9b308bda1c1654d852c9084aa880f5d9f87123a15eb7a95
|
7
|
+
data.tar.gz: 7d423b1259a76f6717a84f9aee5b3d23c0ae4696eaea6efb5e415002411683b65f73dd59f16549270b6aa640ce36beb9f7505fb5204a4581b520139ceb72857e
|
data/CHANGES.md
CHANGED
data/lib/trailblazer/circuit.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
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
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class Trailblazer::Circuit
|
2
2
|
module Task
|
3
|
-
module_function
|
4
3
|
# Convenience functions for tasks. Totally optional.
|
5
4
|
|
6
5
|
# Task::Binary aka "step"
|
@@ -10,38 +9,10 @@ class Trailblazer::Circuit
|
|
10
9
|
#
|
11
10
|
# Returns task to call the proc with (options, flow_options), omitting `direction`.
|
12
11
|
# When called, the task always returns a direction signal.
|
13
|
-
def Binary(step, on_true=Right, on_false=Left)
|
12
|
+
def self.Binary(step, on_true=Right, on_false=Left)
|
14
13
|
->(direction, *args) do # Activity/Task interface.
|
15
14
|
[ step.(direction, *args) ? on_true : on_false, *args ] # <=> Activity/Task interface
|
16
15
|
end
|
17
16
|
end
|
18
|
-
|
19
|
-
module Args
|
20
|
-
module_function
|
21
|
-
# :private:
|
22
|
-
# Return task to call the proc with keyword arguments. Ruby >= 2.0.
|
23
|
-
# This is used by `Operation::step` to wrap the argument and make it
|
24
|
-
# callable in the circuit.
|
25
|
-
def KW(proc)
|
26
|
-
if proc.is_a? Symbol
|
27
|
-
->(*args) { meth!(proc, *args) } # Activity interface
|
28
|
-
else
|
29
|
-
->(*args) { call!(proc, *args) } # Activity interface
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# DISCUSS: standardize tmp_options.
|
34
|
-
# Calls `proc` with a step interface.
|
35
|
-
def call!(proc, direction, options, flow_options, tmp_options={})
|
36
|
-
# proc.(options, **options.to_hash(tmp_options))
|
37
|
-
proc.(options, **options.to_hash)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Make the context's instance method a "lambda" and reuse #call!.
|
41
|
-
# TODO: should we make :context a kwarg?
|
42
|
-
def meth!(proc, direction, options, flow_options, *args)
|
43
|
-
call!(flow_options[:exec_context].method(proc), direction, options, flow_options, *args)
|
44
|
-
end
|
45
|
-
end
|
46
17
|
end
|
47
18
|
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.7
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,6 +98,7 @@ 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
|
101
102
|
- lib/trailblazer/circuit/present.rb
|
102
103
|
- lib/trailblazer/circuit/task.rb
|
103
104
|
- lib/trailblazer/circuit/testing.rb
|