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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b52e8d764a309e9a8977564a19ddf387c236aea0
4
- data.tar.gz: ae086ee946f06831f4f513bbaae68292864787c4
3
+ metadata.gz: 51251c5182357e83918081e911da91c2ead537d0
4
+ data.tar.gz: 4f3087460b00f9e90b0d9584fde259d14cc20f2b
5
5
  SHA512:
6
- metadata.gz: e76bc0e1ce8ea6a5a14563826947b81ea3223b2cbc8aee0b1f9fd1d54d7414fd43f1f8a8a071500fb9b308bda1c1654d852c9084aa880f5d9f87123a15eb7a95
7
- data.tar.gz: 7d423b1259a76f6717a84f9aee5b3d23c0ae4696eaea6efb5e415002411683b65f73dd59f16549270b6aa640ce36beb9f7505fb5204a4581b520139ceb72857e
6
+ metadata.gz: ef71bb646ac59d02d36a71644e7dd47cbbb91498495f03abe2a06853a0a4a050862fab8c985d2c0caeb0ae3e9aeab2dc1d5124731408d846b0bd769d8fffb650
7
+ data.tar.gz: dc0a566ee9e12352a7fa2c1accda1eb443967e10ab2f162752e8e15b223a1b7dd31f8d9f3b93c58f4178991c46f3e180a00c7d20098bb11638c1a45f11408ab1
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.8
2
+
3
+ * Make `Trailblazer::Option` and `Trailblazer::Option::KW` a mix of lambda and object so it's easily extendable.
4
+
1
5
  # 0.0.7
2
6
 
3
7
  * It is now `Trailblazer::Args`.
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem "minitest-line"
7
+ gem "benchmark-ips"
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Circuit
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -120,7 +120,7 @@ end
120
120
 
121
121
  require "trailblazer/circuit/activity"
122
122
  require "trailblazer/circuit/task"
123
- require "trailblazer/circuit/args"
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.7
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-16 00:00:00.000000000 Z
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