trailblazer-core-utils 0.0.9 → 0.0.10

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: 8544eeca330d5bad0b1a70c71a6faa5f6d9c499f4c7bf667f2263f47cdb50519
4
- data.tar.gz: b3d0c1aab3fa5a94a516f73609865b12c900ae25b22de24851aa7b0a42f75e83
3
+ metadata.gz: 5d7beea6c313b9fd73a8cdbb9dce341aae791b0f08d985b09d4b9b0c764ef8aa
4
+ data.tar.gz: cdb5955871270e86d31debd65e2d382b8deb26841f9399bac410776ccb46f8f3
5
5
  SHA512:
6
- metadata.gz: 67449938aae87b065f802edba73033947841d07201484c8462e6da463a349357f657e4f1b1dc0717ffa90cbef278d915cde52d737661e27cf1cfc6cbd27132cf
7
- data.tar.gz: 0db12d0c7f182997729479db38a172ba11baf3eb7026d2d43817a35a18739064b69ffc224902bf57431e419ea64fc7e92b34b5c594a499c72b6a5ba63c13eefa
6
+ metadata.gz: 054bf6edef930665cf3c13cf50cdbe1b4385d526ea3ed13ca1e27705f9f82ebab43051fbfa150dbb371703bae58c2900717b4b9897bad3eafde5e6e562a31cbd
7
+ data.tar.gz: 23566b8f3c8f9a31568820527d5b45d6ec8d67c9b0922a6b357bffef24637553da0d7b85fd7382e2679ea872ee97dd1f8cf8acb74a4202e13b0697598d9e6a83
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ ## [0.0.10]
2
+
1
3
  ## [0.0.9]
2
4
 
3
5
  * Move `#render_task` to `Assertions` module.
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  source "https://rubygems.org"
4
2
 
5
3
  # Specify your gem's dependencies in trailblazer-core-utils.gemspec
@@ -8,3 +6,11 @@ gemspec
8
6
  gem "rake", "~> 13.0"
9
7
 
10
8
  gem "minitest", "~> 5.0"
9
+ gem "minitest-line"
10
+ gem "trailblazer-activity", path: "../trailblazer-activity"
11
+ gem "trailblazer-circuit", path: "../trailblazer-circuit"
12
+ gem "trailblazer-activity-dsl", path: "../trailblazer-activity-dsl-linear"
13
+
14
+ # gem "trailblazer-circuit", github: "trailblazer/trailblazer-circuit", branch: "3-0-dev"
15
+ # gem "trailblazer-activity", github: "trailblazer/trailblazer-activity"#, branch: "3-0-dev"
16
+ # gem "trailblazer-activity-dsl", github: "trailblazer/trailblazer-activity-dsl", branch: "3-0-dev"
@@ -0,0 +1,10 @@
1
+ module Trailblazer
2
+ module Core::Utils
3
+ module AssertEqual
4
+ # FIXME: test me.
5
+ def assert_equal(asserted, expected, *args)
6
+ super(expected, asserted, *args)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ module Trailblazer
2
+ module Core::Utils
3
+ module AssertRun
4
+ # DISCUSS: use Invoke.call() here?
5
+ def assert_run(circuit = nil, node: nil, terminus: nil, seq: nil, flow_options: {}, signal: nil, circuit_options: {runner: Trailblazer::Circuit::Node::Runner}, target_ctx: {seq: []}, expected_target_variables: {}, **lib_ctx)
6
+ # If circuit isn't a Node instance already, wrap it in a "canonical node".
7
+ canonical_node = node ? node : Trailblazer::Circuit::Node[circuit, Trailblazer::Circuit::Processor] # TODO: remove :node and figure it out automatically.
8
+
9
+ # circuit_options = {runner: runner}.merge(circuit_options)
10
+ runner = circuit_options.fetch(:runner)
11
+ circuit_options = circuit_options.merge(node: canonical_node)
12
+ circuit_options = circuit_options.merge(context_implementation: Trailblazer::Circuit::Context) # FIXME: remove
13
+
14
+ lib_ctx = lib_ctx.merge(target_ctx: target_ctx)
15
+
16
+ # TODO: use the public Invoke.call API! will save us some lines of code above.
17
+ # lib_ctx, flow_options, signal = Activity::Invoke.invoke_runner(lib_ctx, flow_options, signal, **circuit_options)
18
+ lib_ctx, flow_options, signal = runner.(lib_ctx, flow_options, signal, **circuit_options)
19
+
20
+ if terminus.is_a?(Symbol)
21
+ terminus = circuit.to_h[:outputs].fetch(terminus).signal
22
+ end
23
+
24
+ assert_equal signal, terminus, "Expected terminus #{terminus.inspect} does not match actual #{signal.inspect}"
25
+
26
+ target_ctx = lib_ctx[:target_ctx]
27
+
28
+ assert_equal target_ctx[:seq], seq, ":seq does not match" # FIXME: test all ctx variables.
29
+
30
+ # if expected_target_ctx
31
+ # assert_equal target_ctx, expected_target_ctx
32
+ # end
33
+ expected_target_variables.each do |k, v| # TODO: test me. what about exception, is it readable?
34
+ assert_equal target_ctx[k], v
35
+ end
36
+
37
+ return lib_ctx, flow_options, signal
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ # FIXME: test **lib_ctx
@@ -11,8 +11,9 @@ module Trailblazer
11
11
  module_function
12
12
 
13
13
  names.each do |name|
14
- define_method(name) do |ctx, **|
15
- ctx[:seq] << name
14
+ define_method(name) do |ctx, seq:, **|
15
+ ctx[:seq] = seq + [name]
16
+
16
17
  ctx.key?(name) ? ctx[name] : true
17
18
  end
18
19
  end
@@ -23,20 +24,21 @@ module Trailblazer
23
24
  #
24
25
  # @example
25
26
  # task task: T.def_task(:create)
26
- def self.def_task(name)
27
- def_tasks(name).method(name)
27
+ def self.def_task(name, **options)
28
+ def_tasks(name, **options).method(name)
28
29
  end
29
30
 
30
- def self.def_tasks(*names)
31
+ def self.def_tasks(*names, success_signal: Activity::Right)
31
32
  Module.new do
32
33
  module_function
33
34
 
34
35
  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
36
+ define_method(name) do |ctx, flow_options, _signal, target_ctx:, **|
37
+ seq = target_ctx[:seq] + [name]
38
+
39
+ signal = target_ctx.key?(name) ? target_ctx[name] : success_signal
38
40
 
39
- return signal, [ctx, flow_options]
41
+ return ctx.merge(target_ctx: target_ctx.merge(seq: seq)), flow_options, signal
40
42
  end
41
43
  end
42
44
  end
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Core
3
3
  module Utils
4
- VERSION = "0.0.9"
4
+ VERSION = "0.0.10"
5
5
  end
6
6
  end
7
7
  end
@@ -1,10 +1,8 @@
1
1
  require "forwardable"
2
- require "trailblazer/core/utils/convert_operation_test"
3
- require "trailblazer/core/utils/symbol_inspect_for"
4
- require "trailblazer/core/utils/inspect"
5
2
  require "trailblazer/core/utils/strip"
6
3
  require "trailblazer/core/utils/def_steps"
7
- require "trailblazer/core/utils/assertions"
4
+ require "trailblazer/core/utils/assert_run"
5
+ require "trailblazer/core/utils/assert_equal"
8
6
 
9
7
  module Trailblazer
10
8
  module Core
@@ -14,10 +12,9 @@ module Trailblazer
14
12
 
15
13
  class << self
16
14
  extend Forwardable
17
- def_delegator Utils::ConvertOperationTest, :call, :convert_operation_test
18
- def_delegator Utils, :symbol_inspect_for
19
15
  def_delegator Utils::DefSteps, :def_steps
20
16
  def_delegator Utils::DefSteps, :def_tasks
17
+ def_delegator Utils::DefSteps, :def_task
21
18
  end
22
19
  end
23
20
  end
metadata CHANGED
@@ -1,30 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-core-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-08-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: trailblazer-activity-dsl-linear
13
+ name: trailblazer-circuit
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: 1.0.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: '0'
27
- description:
28
+ version: 1.0.0
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: 1.1.0
28
32
  email:
29
33
  - apotonick@gmail.com
30
34
  executables: []
@@ -37,19 +41,16 @@ files:
37
41
  - Rakefile
38
42
  - lib/trailblazer/core.rb
39
43
  - lib/trailblazer/core/utils.rb
40
- - lib/trailblazer/core/utils/assertions.rb
41
- - lib/trailblazer/core/utils/convert_operation_test.rb
44
+ - lib/trailblazer/core/utils/assert_equal.rb
45
+ - lib/trailblazer/core/utils/assert_run.rb
42
46
  - lib/trailblazer/core/utils/def_steps.rb
43
- - lib/trailblazer/core/utils/inspect.rb
44
47
  - lib/trailblazer/core/utils/strip.rb
45
- - lib/trailblazer/core/utils/symbol_inspect_for.rb
46
48
  - lib/trailblazer/core/utils/version.rb
47
49
  homepage: https://trailblazer.to
48
50
  licenses: []
49
51
  metadata:
50
52
  homepage_uri: https://trailblazer.to
51
53
  source_code_uri: https://github.com/trailblazer/trailblazer-core-utils
52
- post_install_message:
53
54
  rdoc_options: []
54
55
  require_paths:
55
56
  - lib
@@ -57,15 +58,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - ">="
59
60
  - !ruby/object:Gem::Version
60
- version: 2.5.0
61
+ version: 3.0.0
61
62
  required_rubygems_version: !ruby/object:Gem::Requirement
62
63
  requirements:
63
64
  - - ">="
64
65
  - !ruby/object:Gem::Version
65
66
  version: '0'
66
67
  requirements: []
67
- rubygems_version: 3.5.22
68
- signing_key:
68
+ rubygems_version: 4.0.17
69
69
  specification_version: 4
70
70
  summary: Utilities for Trailblazer core developers.
71
71
  test_files: []
@@ -1,70 +0,0 @@
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: method(:render_task))
60
- end
61
-
62
- module_function
63
- # Use this in {#Cct}.
64
- def render_task(proc)
65
- Activity::Introspect.render_task(proc)
66
- end
67
- end
68
-
69
- end
70
- end
@@ -1,95 +0,0 @@
1
- module Trailblazer
2
- module Core
3
- module Utils
4
- # Convert an Activity test into an operation test.
5
- # Store at {:target}
6
- #
7
- # {#~ctx_to_result} allows to always convert ctx to result within the block.
8
-
9
- # TODO: add {skip}
10
- module ConvertOperationTest
11
- def self.call(filepath, target:, source_gem:)
12
- within_marker = false
13
- within_ignore = false
14
- within_ctx_to_result = false
15
- within_keep = false
16
-
17
- op_test =
18
- File.foreach(filepath).collect do |line|
19
- if line.match(/#:[\w]+/) # FIXME: we don't use this!
20
- within_marker = true
21
- end
22
- if line.match(/#:.+ end/)
23
- within_marker = false
24
- end
25
-
26
- if line.match(/#~keep$/)
27
- within_keep = true
28
- end
29
- if line.match(/#~keep end/)
30
- within_keep = false
31
- end
32
-
33
- if line.match(/#~ignore/)
34
- within_ignore = true
35
- end
36
- if line.match(/#~ignore end/)
37
- within_ignore = false
38
- end
39
-
40
- if line.match(/#~ctx_to_result/)
41
- within_ctx_to_result = true
42
- end
43
- if line.match(/#~ctx_to_result end/)
44
- within_ctx_to_result = false
45
- end
46
-
47
- if within_ignore
48
- # puts "@@@@@ #{line.inspect}"
49
- line = ""
50
- elsif within_keep
51
- line
52
- else
53
- if match = line.match(/#!hint (.+)/)
54
- ws = line.match(/^(\s+)/) # Find out number of whitespace before code starts.
55
-
56
- line = (" " * ws[1].size) + match[1] + "\n"
57
- else
58
- line = line.sub("< Trailblazer::Activity::Railway", "< Trailblazer::Operation")
59
- line = line.sub("< Trailblazer::Activity::FastTrack", "< Trailblazer::Operation")
60
- line = line.gsub("::Activity", "::Operation")
61
-
62
- # if within_marker
63
- line = line.sub("signal, (ctx, _) =", "result =")
64
- if within_ctx_to_result
65
- line = line.sub("ctx[", "result[")
66
- end
67
-
68
- if match = line.match(/(Trailblazer::Operation\.\(([\w:]+), ?)/)
69
- activity = match[2]
70
- line = line.sub(match[0], "#{activity}.(")
71
- end
72
-
73
- if match = line.match(/(\s+)puts signal.+(:\w+)>/)
74
- semantic = match[2]
75
- line = "#{match[1]}result.success? # => #{semantic == ":success" ? true : false}\n"
76
- end
77
- end
78
- # end
79
-
80
- line = line.sub("assert_equal ctx", "assert_equal result")
81
- line = line.sub("assert_equal signal", "assert_equal result.terminus")
82
- end
83
-
84
- line
85
- end
86
-
87
- op_test.insert(0, "# THIS FILE IS AUTOGENERATED FROM #{source_gem}/#{filepath}\n")
88
-
89
- File.write target, op_test.join("")
90
- end
91
-
92
- end # ConvertOperationTest
93
- end
94
- end
95
- end
@@ -1,21 +0,0 @@
1
- module Trailblazer
2
- module Core
3
- module Utils
4
- def self.inspect(object)
5
- return Inspect.convert_hash_inspect(object) if object.is_a?(String)
6
- return object.inspect unless object.is_a?(Hash)
7
-
8
- old_string = object.inspect
9
-
10
- Inspect.convert_hash_inspect(old_string)
11
- end
12
-
13
- module Inspect
14
- def self.convert_hash_inspect(hash_inspect)
15
- new_string = hash_inspect.gsub(/({|, )(\w+): /, '\1:\2=>')
16
- new_string.gsub(" => ", "=>")
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,14 +0,0 @@
1
- module Trailblazer
2
- module Core
3
- module Utils
4
- # Used to test {missing keyword} exceptions in all Ruby versions.
5
- def self.symbol_inspect_for(name)
6
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7.0") || RUBY_ENGINE == 'jruby'
7
- "#{name}"
8
- else
9
- ":#{name}"
10
- end
11
- end
12
- end
13
- end
14
- end