trailblazer-core-utils 0.0.7 → 0.0.8
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/trailblazer/core/utils/assertions.rb +68 -0
- data/lib/trailblazer/core/utils/def_steps.rb +46 -0
- data/lib/trailblazer/core/utils/version.rb +1 -1
- data/lib/trailblazer/core.rb +4 -0
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0786b99461164892b7ff976597820ffd9892f97b2f6aa11d2ada59e98b0b9856'
|
4
|
+
data.tar.gz: 39b60eef74d5a4af000aa24798908557392d49ec2155593753b112047be4bea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c258c2fdeaa80ad702598b049af9c352821edb100f5e2506e107b93b79bc5b008d6aab28552b6640ea4e56b1f9b0ba3656d5ab911c8eda13482de6221f3583e
|
7
|
+
data.tar.gz: bd842eb0300aea0fd82c41aff9c62a76be0576add12aeabfcfdd95c487d3407ed4aeeadb9fc7ff01d6febb5d45a36ef6b6fc4fc7bf135e380d621f98d8dc34da
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
module Core::Utils
|
3
|
+
module Assertions
|
4
|
+
# `:seq` is always passed into ctx.
|
5
|
+
# @param :seq String What the {:seq} variable in the result ctx looks like. (expected seq)
|
6
|
+
# @param :expected_ctx_variables Variables that are added during the call by the asserted activity.
|
7
|
+
def assert_call(activity, terminus: :success, seq: "[]", expected_ctx_variables: {}, **ctx_variables)
|
8
|
+
# Call without taskWrap!
|
9
|
+
signal, (ctx, _) = activity.([{seq: [], **ctx_variables}, _flow_options = {}]) # simply call the activity with the input you want to assert.
|
10
|
+
|
11
|
+
assert_call_for(signal, ctx, terminus: terminus, seq: seq, **expected_ctx_variables, **ctx_variables)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Use {TaskWrap.invoke} to call the activity.
|
15
|
+
def assert_invoke(activity, terminus: :success, seq: "[]", circuit_options: {}, flow_options: {}, expected_ctx_variables: {}, **ctx_variables)
|
16
|
+
signal, (ctx, returned_flow_options) = Activity::TaskWrap.invoke(
|
17
|
+
activity,
|
18
|
+
[
|
19
|
+
{seq: [], **ctx_variables},
|
20
|
+
flow_options,
|
21
|
+
],
|
22
|
+
**circuit_options
|
23
|
+
)
|
24
|
+
|
25
|
+
assert_call_for(signal, ctx, terminus: terminus, seq: seq, **ctx_variables, **expected_ctx_variables) # DISCUSS: ordering of variables?
|
26
|
+
|
27
|
+
return signal, [ctx, returned_flow_options]
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_call_for(signal, ctx, terminus: :success, seq: "[]", **ctx_variables)
|
31
|
+
assert_equal signal.to_h[:semantic], terminus, "assert_call expected #{terminus} terminus, not #{signal}. Use assert_call(activity, terminus: #{signal.to_h[:semantic].inspect})"
|
32
|
+
|
33
|
+
assert_equal ctx.inspect, {seq: "%%%"}.merge(ctx_variables).inspect.sub('"%%%"', seq)
|
34
|
+
|
35
|
+
return ctx
|
36
|
+
end
|
37
|
+
|
38
|
+
# Tests {:circuit} and {:outputs} fields so far.
|
39
|
+
def assert_process_for(process, *args)
|
40
|
+
semantics, circuit = args[0..-2], args[-1]
|
41
|
+
|
42
|
+
assert_equal semantics.sort, process.to_h[:outputs].collect { |output| output[:semantic] }.sort
|
43
|
+
|
44
|
+
assert_circuit(process, circuit)
|
45
|
+
|
46
|
+
process
|
47
|
+
end
|
48
|
+
|
49
|
+
alias_method :assert_process, :assert_process_for
|
50
|
+
|
51
|
+
def assert_circuit(schema, circuit)
|
52
|
+
cct = Cct(schema)
|
53
|
+
|
54
|
+
cct = cct.gsub("#<Trailblazer::Activity::TaskBuilder::Task user_proc=", "<*")
|
55
|
+
assert_equal circuit.to_s, cct
|
56
|
+
end
|
57
|
+
|
58
|
+
def Cct(activity)
|
59
|
+
Activity::Introspect::Render.(activity, inspect_task: Assertions.method(:render_task))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Use this in {#Cct}.
|
64
|
+
def self.render_task(proc)
|
65
|
+
Activity::Introspect.render_task(proc)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
module Core::Utils
|
3
|
+
# Helpers to quickly create steps and tasks.
|
4
|
+
module DefSteps
|
5
|
+
# Creates a module with one step method for each name.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# extend T.def_steps(:create, :save)
|
9
|
+
def self.def_steps(*names)
|
10
|
+
Module.new do
|
11
|
+
module_function
|
12
|
+
|
13
|
+
names.each do |name|
|
14
|
+
define_method(name) do |ctx, **|
|
15
|
+
ctx[:seq] << name
|
16
|
+
ctx.key?(name) ? ctx[name] : true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates a method instance with a task interface.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# task task: T.def_task(:create)
|
26
|
+
def self.def_task(name)
|
27
|
+
def_tasks(name).method(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.def_tasks(*names)
|
31
|
+
Module.new do
|
32
|
+
module_function
|
33
|
+
|
34
|
+
names.each do |name|
|
35
|
+
define_method(name) do |(ctx, flow_options), **|
|
36
|
+
ctx[:seq] << name
|
37
|
+
signal = ctx.key?(name) ? ctx[name] : Activity::Right
|
38
|
+
|
39
|
+
return signal, [ctx, flow_options]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/trailblazer/core.rb
CHANGED
@@ -3,6 +3,8 @@ require "trailblazer/core/utils/convert_operation_test"
|
|
3
3
|
require "trailblazer/core/utils/symbol_inspect_for"
|
4
4
|
require "trailblazer/core/utils/inspect"
|
5
5
|
require "trailblazer/core/utils/strip"
|
6
|
+
require "trailblazer/core/utils/def_steps"
|
7
|
+
require "trailblazer/core/utils/assertions"
|
6
8
|
|
7
9
|
module Trailblazer
|
8
10
|
module Core
|
@@ -14,6 +16,8 @@ module Trailblazer
|
|
14
16
|
extend Forwardable
|
15
17
|
def_delegator Utils::ConvertOperationTest, :call, :convert_operation_test
|
16
18
|
def_delegator Utils, :symbol_inspect_for
|
19
|
+
def_delegator Utils::DefSteps, :def_steps
|
20
|
+
def_delegator Utils::DefSteps, :def_tasks
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-core-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
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: 2025-
|
12
|
-
dependencies:
|
11
|
+
date: 2025-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: trailblazer-activity-dsl-linear
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description:
|
14
28
|
email:
|
15
29
|
- apotonick@gmail.com
|
@@ -23,7 +37,9 @@ files:
|
|
23
37
|
- Rakefile
|
24
38
|
- lib/trailblazer/core.rb
|
25
39
|
- lib/trailblazer/core/utils.rb
|
40
|
+
- lib/trailblazer/core/utils/assertions.rb
|
26
41
|
- lib/trailblazer/core/utils/convert_operation_test.rb
|
42
|
+
- lib/trailblazer/core/utils/def_steps.rb
|
27
43
|
- lib/trailblazer/core/utils/inspect.rb
|
28
44
|
- lib/trailblazer/core/utils/strip.rb
|
29
45
|
- lib/trailblazer/core/utils/symbol_inspect_for.rb
|
@@ -48,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
64
|
- !ruby/object:Gem::Version
|
49
65
|
version: '0'
|
50
66
|
requirements: []
|
51
|
-
rubygems_version: 3.
|
67
|
+
rubygems_version: 3.5.22
|
52
68
|
signing_key:
|
53
69
|
specification_version: 4
|
54
70
|
summary: Utilities for Trailblazer core developers.
|