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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5dc593717272d4f702fc5f2f9f0ba48481cfbad
4
- data.tar.gz: 108fd37110388fb3d4d45f79787ab284e7434b3a
3
+ metadata.gz: b52e8d764a309e9a8977564a19ddf387c236aea0
4
+ data.tar.gz: ae086ee946f06831f4f513bbaae68292864787c4
5
5
  SHA512:
6
- metadata.gz: 69bbd08cd6cba1c394bc5da24c4d1df1cf7cf6420a3a60c23caf085bd627d5460ffe9c965d7f703466b37f3756347b220c3f8d1fcbf6ddf06abab5b1b6dc220e
7
- data.tar.gz: 1714df50a75d590b5ce04c914b1ab0ac6910bf583998551b577697367a22ca69d43d8e47ba8f5b8bb04bbc868c140f5d16bfc0cb7c3f9cd0dd2f3d178da1dd5b
6
+ metadata.gz: e76bc0e1ce8ea6a5a14563826947b81ea3223b2cbc8aee0b1f9fd1d54d7414fd43f1f8a8a071500fb9b308bda1c1654d852c9084aa880f5d9f87123a15eb7a95
7
+ data.tar.gz: 7d423b1259a76f6717a84f9aee5b3d23c0ae4696eaea6efb5e415002411683b65f73dd59f16549270b6aa640ce36beb9f7505fb5204a4581b520139ceb72857e
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.7
2
+
3
+ * It is now `Trailblazer::Args`.
4
+
1
5
  # 0.0.6
2
6
 
3
7
  * `Wrapped` is now `Wrap`. Also, a consistent `Alterations` interface allows tweaking here.
@@ -120,6 +120,7 @@ end
120
120
 
121
121
  require "trailblazer/circuit/activity"
122
122
  require "trailblazer/circuit/task"
123
+ require "trailblazer/circuit/args"
123
124
  require "trailblazer/circuit/alter"
124
125
  require "trailblazer/circuit/trace"
125
126
  require "trailblazer/circuit/present"
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Trailblazer
2
2
  class Circuit
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  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.6
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-12 00:00:00.000000000 Z
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