Skip to content

Commit 0cd0ead

Browse files
committed
coming up with some combined interface that transports the three usual arguments,
plus a processed "value" plus handy keyword arguments of the "library ctx". feels better.
1 parent 38f6e82 commit 0cd0ead

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

lib/trailblazer/activity/circuit/step.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,11 @@ def self.Step(filter_with_step_interface, **options)
135135

136136

137137
class Step___ < Struct.new(:user_filter, :binary?)
138-
def self.invoke_callable_with_step_interface(ctx, flow_options, circuit_options)
139-
callable = ctx[:callable]
138+
def self.invoke_callable_with_step_interface(ctx, flow_options, circuit_options, callable, **kwargs)
140139

141-
application_ctx = ctx[:application_ctx]
140+
result = callable.(ctx, **ctx.to_h) # This is how any Step should be called!
142141

143-
_result = callable.(application_ctx, **application_ctx.to_h) # This is how any Step should be called!
144-
145-
ctx[:result] = _result
146-
147-
return ctx, flow_options, Trailblazer::Activity::Right
142+
return ctx, flow_options, result
148143
end
149144

150145
class Binary < Struct.new(:step)
@@ -161,12 +156,10 @@ def self.compute_signal(ctx, flow_options, result)
161156
end
162157

163158

164-
def self.___compute_signal(ctx, flow_options, circuit_options)
165-
result = ctx.fetch(:result) # we're a step, {result} is always a "boolean".
166-
159+
def self.___compute_signal(ctx, flow_options, circuit_options, result, **)
160+
# we're a step, {result} is always a "boolean".
167161
signal = Binary.binary_signal_for(result, Activity::Right, Activity::Left)
168162

169-
ctx[:result] = [ctx, flow_options, signal]
170163
return ctx, flow_options, signal
171164
end
172165

test/circuit_step_test.rb

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,38 +128,44 @@ def self.call(ctx, outcome:, **)
128128
assert_equal CU.strip(CU.inspect(ctx)), %({:params=>{:id=>1}, :action=>:update})
129129
assert_equal signal, {id: 1, exec_context: self} # the handler returns a Hash as a signal?
130130

131-
ctx, _ = Trailblazer::Activity::Circuit::Step___::Step___Activity___InstanceMethod.(
132-
{
133-
application_ctx: self.ctx,
131+
ctx, _flow_options, signal = Trailblazer::Activity::Circuit::Processor.(
132+
Trailblazer::Activity::Circuit::Step___::Step___Activity___InstanceMethod,
133+
self.ctx,
134+
{},
135+
{exec_context: self},
136+
"value",
137+
**library_ctx = {
134138
method_name: :my_handler_with_step_interface,
135-
}, {}, {exec_context: self}
139+
}
136140
)
137141

138-
assert_equal CU.strip(CU.inspect(ctx[:application_ctx]))[0..18], %({:params=>{:id=>1},) # FIXME.
142+
assert_equal CU.strip(CU.inspect(ctx)), %({:params=>{:id=>1}, :action=>:update, :captured_params=>\"{:id=>1}\"})
143+
assert_equal CU.inspect(signal), %({:id=>1})
139144

140-
ctx, flow_options, signal = Trailblazer::Activity::Circuit::Step___::Step___Activity___InstanceMethod___Binary.(
141-
{
142-
application_ctx: {outcome: false, params: {id: 1}},
145+
ctx, _flow_options, signal = Trailblazer::Activity::Circuit::Processor.(
146+
Trailblazer::Activity::Circuit::Step___::Step___Activity___InstanceMethod___Binary,
147+
{outcome: false, params: {id: 1}},
148+
{},
149+
{exec_context: self},
150+
"value",
151+
**library_ctx = {
143152
method_name: :my_binary_step_handler,
144-
}, {}, {exec_context: self}
153+
}
145154
)
146155

147-
signal = ctx[:result][2] # FIXME: hm.
148-
ctx = ctx[:application_ctx]
149156
assert_equal signal, Trailblazer::Activity::Left
150-
assert_equal CU.strip(CU.inspect(ctx)), %({:outcome=>false, :params=>{:id=>1}, :my_binary_step_handler=>true})
157+
assert_equal CU.inspect(ctx), %({:outcome=>false, :params=>{:id=>1}, :my_binary_step_handler=>true})
151158

152-
ctx, flow_options, signal = Trailblazer::Activity::Circuit::Step___::Step___Activity___Binary.(
153-
{
154-
application_ctx: {outcome: false, params: {id: 1}},
155-
callable: MyBinaryStepHandler,
156-
}, {}, {exec_context: self}
159+
ctx, _flow_options, signal = Trailblazer::Activity::Circuit::Processor.(
160+
Trailblazer::Activity::Circuit::Step___::Step___Activity___Binary,
161+
{outcome: false, params: {id: 1}},
162+
{},
163+
{exec_context: self},
164+
MyBinaryStepHandler,
157165
)
158166

159-
signal = ctx[:result][2] # FIXME: hm.
160-
ctx = ctx[:application_ctx]
161167
assert_equal signal, Trailblazer::Activity::Left
162-
assert_equal CU.strip(CU.inspect(ctx)), %({:outcome=>false, :params=>{:id=>1}, :my_binary_step_handler=>true}) # FIXME.
168+
assert_equal CU.inspect(ctx), %({:outcome=>false, :params=>{:id=>1}, :my_binary_step_handler=>true})
163169
end
164170

165171
it "Circuit::Step with step interface, no binary, returning a value, only" do

0 commit comments

Comments
 (0)