Skip to content

Commit f4d8c61

Browse files
committed
don't use old Inject() => {}.
replace :override with :replace.
1 parent e85ab6b commit f4d8c61

File tree

7 files changed

+20
-23
lines changed

7 files changed

+20
-23
lines changed

lib/trailblazer/macro/each.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def self.Each(block_activity=nil, dataset_from: nil, item_key: :item, id: Macro.
1414
# filter to set ctx[:index]
1515
# The interesting part here is that we read dynamic values from the {circuit_options}, to not
1616
# pollute the business ctx.
17-
my_lowlevel_inject_filter = ->((ctx, flow_options), index:, **circuit_options) { [index, ctx] }
17+
my_lowlevel_inject_filter = ->((ctx, flow_options), index:, **circuit_options) { [{index: index}, ctx] }
1818
my_filter_builder = ->(*) { Trailblazer::Activity::DSL::Linear::VariableMapping::SetVariable.new(name: "bla.FIXME", filter: my_lowlevel_inject_filter, write_name: :index, user_filter: nil) }
1919
# filter to set ctx[item_key]
20-
my_lowlevel_inject_filter_item = ->((ctx, flow_options), item:, **circuit_options) { [item, ctx] }
20+
my_lowlevel_inject_filter_item = ->((ctx, flow_options), item:, **circuit_options) { [{item_key => item}, ctx] }
2121
my_filter_builder_item = ->(*) { Trailblazer::Activity::DSL::Linear::VariableMapping::SetVariable.new(name: "bla.FIXME.item_key", filter: my_lowlevel_inject_filter_item, write_name: item_key, user_filter: nil) }
2222

2323
# DISCUSS: move to Wrap.
@@ -121,7 +121,7 @@ def self.options_for_dataset_from(dataset_from:)
121121
def self.compute_runtime_id(ctx, trace_node:, activity:, compile_id:, **)
122122
# activity is the iterated activity
123123
fields = activity.to_h[:fields]
124-
return compile_id unless fields && fields[:each] == true
124+
return unless fields && fields[:each] == true
125125

126126
# Developer::Trace::Snapshot::Ctx.ctx_snapshot_for(trace_node.snapshot_before, .data
127127
# FIXME: BETTER API, we need access to stack now
@@ -130,7 +130,7 @@ def self.compute_runtime_id(ctx, trace_node:, activity:, compile_id:, **)
130130
# index = trace_node.snapshot_before.data[:ctx_snapshot].fetch(:index)
131131
index = trace_node.snapshot_before.data[:ctx_variable_changeset].find { |name, version, value| name == :index }[2]
132132

133-
ctx[:runtime_id] = "#{compile_id}.#{index}"
133+
ctx.merge(runtime_id: "#{compile_id}.#{index}")
134134
end
135135
end
136136
end

lib/trailblazer/macro/model.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ def self.Model(model_class = nil, action = :new, find_by_key = :id, id: 'model.b
88
Activity::Railway.Inject() => [:params], # pass-through {:params} if it's in ctx.
99

1010
# defaulting as per Inject() API.
11-
Activity::Railway.Inject() => {
12-
:"model.class" => ->(*) { model_class },
13-
:"model.action" => ->(*) { action },
14-
:"model.find_by_key" => ->(*) { find_by_key },
15-
}
11+
Activity::Railway.Inject(:"model.class") => ->(*) { model_class },
12+
Activity::Railway.Inject(:"model.action") => ->(*) { action },
13+
Activity::Railway.Inject(:"model.find_by_key") => ->(*) { find_by_key },
1614
}
1715

1816
options = {task: task, id: id}.merge(injections)

lib/trailblazer/macro/nested.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ def self.Nested(callable, id: Macro.id_for(callable, macro: :Nested, hint: calla
2020
# DISCUSS: we could use fields{task_wrap_extensions} from the Nested activity here?
2121
task_wrap_extension = Activity::TaskWrap.Extension(*merge)
2222

23-
Activity::Railway.Subprocess(task).merge( # FIXME: allow this directly in Subprocess
24-
id: id,
25-
extensions: [task_wrap_extension],
26-
)
23+
Activity::Railway.Subprocess(task)
24+
.merge( # FIXME: allow this directly in Subprocess
25+
id: id,
26+
Activity::Railway.Extension() => task_wrap_extension,
27+
)
2728
end
2829

2930
# @private

lib/trailblazer/macro/policy.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ def self.step(condition, name: nil, &block)
3232
path = :"policy.#{name}.eval"
3333
task = Eval.new(name: name, path: path)
3434

35-
injections = {
36-
Trailblazer::Activity::Railway.Inject() => {
37-
# :"policy.default.eval"
38-
path => ->(*) { condition }
39-
}
35+
injections = { # :"policy.default.eval"
36+
Trailblazer::Activity::Railway.Inject(path) => ->(*) { condition }
4037
}
4138

4239
{task: task, id: path}.merge(injections)

test/docs/guard_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class DocsGuardProcTest < Minitest::Spec
66
#:proc
77
class Create < Trailblazer::Operation
8-
step Policy::Guard(->(options, pass:, **) { pass })
8+
step Policy::Guard(->(options, pass:, **) { pass }), id: :policy
99
#:pipeonly
1010
step :process
1111

@@ -27,7 +27,7 @@ def process(options, **)
2727
#---
2828
#- Guard inheritance
2929
class New < Create
30-
step Policy::Guard( ->(options, current_user:, **) { current_user } ), override: true
30+
step Policy::Guard( ->(options, current_user:, **) { current_user } ), replace: :policy
3131
end
3232

3333
it { assert_equal Trailblazer::Developer.railway(New), %{[>policy.default.eval,>process]} }

test/docs/pundit_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Create < Trailblazer::Operation
5252
end
5353

5454
#---
55-
#- override
55+
#- replace
5656
class New < Create
5757
step Policy::Pundit( MyPolicy, :new? ), replace: :"policy.default.eval"
5858
end
@@ -72,12 +72,12 @@ class New < Create
7272
#---
7373
#- override with :name
7474
class Edit < Trailblazer::Operation
75-
step Policy::Pundit( MyPolicy, :create?, name: "first" )
75+
step Policy::Pundit( MyPolicy, :create?, name: "first" ), id: "policy.first.eval"
7676
step Policy::Pundit( MyPolicy, :new?, name: "second" )
7777
end
7878

7979
class Update < Edit
80-
step Policy::Pundit( MyPolicy, :new?, name: "first" ), override: true
80+
step Policy::Pundit( MyPolicy, :new?, name: "first" ), replace: "policy.first.eval"
8181
end
8282

8383
it { assert_equal Trailblazer::Developer.railway(Edit), %{[>policy.first.eval,>policy.second.eval]} }

trailblazer-macro.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
1818
spec.require_paths = ["lib"]
1919

2020
spec.add_development_dependency "minitest"
21+
spec.add_development_dependency "minitest-line"
2122
spec.add_development_dependency "rake"
2223
# spec.add_development_dependency "trailblazer-developer", ">= 0.1.0", "< 0.2.0"
2324
# spec.add_dependency "trailblazer-operation", ">= 0.11.0" # TODO: this dependency will be removed. currently needed for tests and for Guard::Result

0 commit comments

Comments
 (0)