trailblazer-operation 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2908ffe1d690d0bd75b1e936b1351a4139405ed43ea43ce560c5b44c6c782e73
4
- data.tar.gz: ee5ee4538ea0d59e266c7600f2ff2de20c79a9d66209063f1bdcb8530e296243
3
+ metadata.gz: bf82f1aa3080dfea1c9165859fdd6de207c9333cc3af7fb8c2e52fff55811ba2
4
+ data.tar.gz: c53369fe71b53e3ac3be42746d438c648b312a4d03956f483abd2d1e7e39cebb
5
5
  SHA512:
6
- metadata.gz: a15078c7427fe6927af8e9782dbd919f60115fa5b4fb7c5aed039c5b3e3cb0ef2737373c797f0937a689b10c50e5089850a1c95d6ba6085483cc6a26d07e718b
7
- data.tar.gz: 5e1a92c16c7ed05500dc28dfa1dccbc352a0d0d9efea28663cb93ff56a4b6e583474fa66062eb88b9fd6008dc84bd56008ebe2f83c8f73d76a688ddaf1fe7fb3
6
+ metadata.gz: 98b29781915fdb5b40921dfd621a59dc580ce708e7ddaaf44b3123ee5a838ffde6a96cbe9b2d0cb24b15b60db3d2f5e166339253612786b96ebf5c5073e28fe6
7
+ data.tar.gz: 1481d504865240aeeee2bd254cfbc927156da7d465a408e42fc8936579984a95a80926356e6b5757d67ce8d814879f6aa22fc1678cd869345ac7be38b40d2e68
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.6.6
2
+
3
+ * Rename `Operation.flow_options` to `Operation.flow_options_for_public_call`.
4
+ * Operations can also accept `flow_options` at run-time now :beers:, giving them precedence over `Operation.flow_options_for_public_call`.
5
+
1
6
  ## 0.6.5
2
7
 
3
8
  * Upgrade `trailblazer-activity` & `trailblazer-activity-dsl-linear` versions to utilise new `trailblazer-context` :drum:
@@ -19,15 +19,23 @@ module Trailblazer
19
19
  call_with_public_interface(options, *args)
20
20
  end
21
21
 
22
- def call_with_public_interface(*args)
23
- ctx = options_for_public_call(*args, flow_options())
22
+ # Default {@activity} call interface which doesn't accept {circuit_options}
23
+ #
24
+ # @param [Array] args => [ctx, flow_options]
25
+ #
26
+ # @return [Operation::Railway::Result]
27
+ #
28
+ # @private
29
+ def call_with_public_interface(options, flow_options = {})
30
+ flow_options = flow_options_for_public_call(flow_options)
31
+ ctx = options_for_public_call(options, flow_options)
24
32
 
25
33
  # call the activity.
26
34
  # This will result in invoking {::call_with_circuit_interface}.
27
35
  # last_signal, (options, flow_options) = Activity::TaskWrap.invoke(self, [ctx, {}], {})
28
36
  signal, (ctx, flow_options) = Activity::TaskWrap.invoke(
29
37
  @activity,
30
- [ctx, flow_options()],
38
+ [ctx, flow_options],
31
39
  exec_context: new
32
40
  )
33
41
 
@@ -36,6 +44,13 @@ module Trailblazer
36
44
  end
37
45
 
38
46
  # This interface is used for all nested OPs (and the outer-most, too).
47
+ #
48
+ # @param [Array] args - Contains [ctx, flow_options]
49
+ # @param [Hash] circuit_options - Options to configure activity circuit
50
+ #
51
+ # @return [signal, [ctx, flow_options]]
52
+ #
53
+ # @private
39
54
  def call_with_circuit_interface(args, circuit_options)
40
55
  strategy_call(args, circuit_options) # FastTrack#call
41
56
  end
@@ -46,13 +61,13 @@ module Trailblazer
46
61
 
47
62
  # Compile a Context object to be passed into the Activity::call.
48
63
  # @private
49
- def self.options_for_public_call(options, **flow_options)
64
+ def self.options_for_public_call(options, flow_options = {})
50
65
  Trailblazer::Context(options, {}, flow_options[:context_options])
51
66
  end
52
67
 
53
68
  # @semi=public
54
- def flow_options
55
- {}
69
+ def flow_options_for_public_call(options = {})
70
+ options
56
71
  end
57
72
  end
58
73
  end
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Version
3
3
  module Operation
4
- VERSION = "0.6.5"
4
+ VERSION = "0.6.6"
5
5
  end
6
6
  end
7
7
  end
@@ -24,7 +24,6 @@ class DocsActivityTest < Minitest::Spec
24
24
  signal.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
25
25
  end
26
26
 
27
- #:describe
28
27
  describe Memo::Create do
29
28
  it "creates a sane Memo instance" do
30
29
  #:call-public
@@ -39,8 +38,64 @@ class DocsActivityTest < Minitest::Spec
39
38
  result.success?.must_equal true
40
39
  result[:model].text.must_equal "Enjoy an IPA"
41
40
  end
41
+
42
+ it "allows indifferent access for ctx keys" do
43
+ #:ctx-indifferent-access
44
+ result = Memo::Create.(params: { text: "Enjoy an IPA" })
45
+
46
+ result[:params] # => { text: "Enjoy an IPA" }
47
+ result['params'] # => { text: "Enjoy an IPA" }
48
+ #:ctx-indifferent-access end
49
+
50
+ result.success?.must_equal true
51
+ result[:params].must_equal({ text: "Enjoy an IPA" })
52
+ result['params'].must_equal({ text: "Enjoy an IPA" })
53
+ end
54
+
55
+ it "allows defining aliases for ctx keys" do
56
+ module AliasesExample
57
+ Memo = Struct.new(:text)
58
+
59
+ module Memo::Contract
60
+ Create = Struct.new(:sync)
61
+ end
62
+
63
+ #:ctx-aliases-step
64
+ class Memo::Create < Trailblazer::Operation
65
+ #~flow
66
+ step ->(ctx, **) { ctx[:'contract.default'] = Memo::Contract::Create.new }
67
+ #~flow end
68
+
69
+ pass :sync
70
+
71
+ def sync(ctx, contract:, **)
72
+ # ctx['contract.default'] == ctx[:contract]
73
+ contract.sync
74
+ end
75
+ end
76
+ #:ctx-aliases-step end
77
+ end
78
+
79
+ #:ctx-aliases
80
+ options = { params: { text: "Enjoy an IPA" } }
81
+ flow_options = {
82
+ context_options: {
83
+ aliases: { 'contract.default': :contract, 'policy.default': :policy },
84
+ container_class: Trailblazer::Context::Container::WithAliases,
85
+ }
86
+ }
87
+
88
+ result = AliasesExample::Memo::Create.(options, flow_options)
89
+
90
+ result['contract.default'] # => Memo::Contract::Create
91
+ result[:contract] # => Memo::Contract::Create
92
+ #:ctx-aliases end
93
+
94
+ result.success?.must_equal true
95
+ _(result[:contract].class).must_equal AliasesExample::Memo::Contract::Create
96
+ _(result['contract.default']).must_equal result[:contract]
97
+ end
42
98
  end
43
- #:describe end
44
99
 
45
100
  it do
46
101
  module J
@@ -79,8 +79,51 @@ class DeclarativeApiTest < Minitest::Spec
79
79
  step ->(options, **) { options["e"] = 2 }
80
80
  end
81
81
 
82
+ class Aliases < Update
83
+ def self.flow_options_for_public_call(*)
84
+ {
85
+ context_options: {
86
+ aliases: { 'b' => :settle },
87
+ container_class: Trailblazer::Context::Container::WithAliases,
88
+ }
89
+ }
90
+ end
91
+ end
92
+
82
93
  it "allows to inherit" do
83
94
  Upsert.("params" => {decide: true}).inspect("a", "b", "c", "d", "e").must_equal %{<Result:true [false, true, nil, 1, nil] >}
84
95
  Unset. ("params" => {decide: true}).inspect("a", "b", "c", "d", "e").must_equal %{<Result:true [false, true, nil, 1, 2] >}
85
96
  end
97
+
98
+ #---
99
+ #- ctx container
100
+ it do
101
+ options = { "params" => {decide: true} }
102
+
103
+ # Default call
104
+ result = Update.(options)
105
+ result.inspect("a", "b", "c").must_equal %{<Result:true [false, true, nil] >}
106
+
107
+ # Circuit interface call
108
+ signal, (ctx, _) = Update.([Update.options_for_public_call(options), {}], {})
109
+
110
+ signal.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
111
+ ctx.inspect.must_equal %{#<Trailblazer::Context::Container wrapped_options={\"params\"=>{:decide=>true}} mutable_options={\"a\"=>false, \"b\"=>true}>}
112
+
113
+ # Call by passing aliases as an argument.
114
+ result = Update.(
115
+ options,
116
+ {
117
+ context_options: {
118
+ aliases: { 'b' => :settle },
119
+ container_class: Trailblazer::Context::Container::WithAliases,
120
+ }
121
+ }
122
+ )
123
+ result[:settle].must_equal true
124
+
125
+ # Set aliases by overriding `flow_options` at the compile time.
126
+ result = Aliases.(options)
127
+ result[:settle].must_equal true
128
+ end
86
129
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-20 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trailblazer-activity-dsl-linear
@@ -177,7 +177,7 @@ homepage: http://trailblazer.to
177
177
  licenses:
178
178
  - MIT
179
179
  metadata: {}
180
- post_install_message:
180
+ post_install_message:
181
181
  rdoc_options: []
182
182
  require_paths:
183
183
  - lib
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubygems_version: 3.0.8
196
- signing_key:
196
+ signing_key:
197
197
  specification_version: 4
198
198
  summary: Trailblazer's operation object with railway flow and integrated error handling.
199
199
  test_files: