trailblazer-core-utils 0.0.1
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 +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/README.md +14 -0
- data/Rakefile +12 -0
- data/lib/trailblazer/core/utils/convert_operation_test.rb +78 -0
- data/lib/trailblazer/core/utils/symbol_inspect_for.rb +14 -0
- data/lib/trailblazer/core/utils/version.rb +7 -0
- data/lib/trailblazer/core/utils.rb +12 -0
- data/lib/trailblazer/core.rb +17 -0
- data/sig/trailblazer/core/utils.rbs +8 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fc15bc9574a978aa4195fabd689b8d9c359c72ad43a1da2c93001e06df285cef
|
4
|
+
data.tar.gz: 336e6e60a0dd6ef4e46600bd31188fc749cd3f2c005f65da67a6771d7018b920
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bac547764b842d9cadf77398088fb885f8bc284a1abbdaed2b9efe6650d4eb8a438e370727182187c0b80ce3bdf3cfb07974f744045af79f7f74a37cdda80aa6
|
7
|
+
data.tar.gz: 8b4fca447de1b17f782482238db9488df31efceb7b6847bf60f858e2e9eb3ca7b3e692b47b34b85c6ad2b4e40faf9a20670396c107b587a8d09112b3337c75a4
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Trailblazer::Core::Utils
|
2
|
+
|
3
|
+
## Convert Activity tests to Operation tests
|
4
|
+
|
5
|
+
In order to show users both `Activity` and `Operation` tests, we have a converter.
|
6
|
+
This implies converted tests are written in a specific style.
|
7
|
+
|
8
|
+
We currently don't use a `bin/` command.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
require "trailblazer/core"
|
12
|
+
Trailblazer::Core.convert_operation_test("test/docs/model_test.rb")
|
13
|
+
Trailblazer::Core.convert_operation_test("test/docs/each_test.rb")
|
14
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
module Core
|
3
|
+
module Utils
|
4
|
+
# Convert an Activity test into an operation test.
|
5
|
+
# Store at {test/docs/autogenerated/operation_model_test.rb}
|
6
|
+
#
|
7
|
+
# {#~ctx_to_result} allows to always convert ctx to result within the block.
|
8
|
+
|
9
|
+
module ConvertOperationTest
|
10
|
+
def self.call(filepath)
|
11
|
+
within_marker = false
|
12
|
+
within_ignore = false
|
13
|
+
within_ctx_to_result = false
|
14
|
+
|
15
|
+
op_test =
|
16
|
+
File.foreach(filepath).collect do |line|
|
17
|
+
if line.match(/#:[\w]+/) # FIXME: we don't use this!
|
18
|
+
within_marker = true
|
19
|
+
end
|
20
|
+
if line.match(/#:.+ end/)
|
21
|
+
within_marker = false
|
22
|
+
end
|
23
|
+
|
24
|
+
if line.match(/#~ignore/) # FIXME: we don't use this!
|
25
|
+
within_ignore = true
|
26
|
+
end
|
27
|
+
if line.match(/#~ignore end/)
|
28
|
+
within_ignore = false
|
29
|
+
end
|
30
|
+
|
31
|
+
if line.match(/#~ctx_to_result/)
|
32
|
+
within_ctx_to_result = true
|
33
|
+
end
|
34
|
+
if line.match(/#~ctx_to_result end/)
|
35
|
+
within_ctx_to_result = false
|
36
|
+
end
|
37
|
+
|
38
|
+
if within_ignore
|
39
|
+
# puts "@@@@@ #{line.inspect}"
|
40
|
+
line = ""
|
41
|
+
else
|
42
|
+
line = line.sub("< Trailblazer::Activity::Railway", "< Trailblazer::Operation")
|
43
|
+
line = line.gsub("::Activity", "::Operation")
|
44
|
+
|
45
|
+
# if within_marker
|
46
|
+
line = line.sub("signal, (ctx, _) =", "result =")
|
47
|
+
if within_ctx_to_result
|
48
|
+
line = line.sub("ctx[", "result[")
|
49
|
+
end
|
50
|
+
|
51
|
+
if match = line.match(/(Trailblazer::Operation\.\(([\w:]+), ?)/)
|
52
|
+
activity = match[2]
|
53
|
+
line = line.sub(match[0], "#{activity}.(")
|
54
|
+
end
|
55
|
+
|
56
|
+
if match = line.match(/(\s+)puts signal.+(:\w+)>/)
|
57
|
+
semantic = match[2]
|
58
|
+
line = "#{match[1]}result.success? # => #{semantic == ":success" ? true : false}\n"
|
59
|
+
end
|
60
|
+
# end
|
61
|
+
|
62
|
+
line = line.sub("assert_equal ctx", "assert_equal result")
|
63
|
+
line = line.sub("assert_equal signal", "assert_equal result.event")
|
64
|
+
end
|
65
|
+
|
66
|
+
line
|
67
|
+
end
|
68
|
+
|
69
|
+
op_test.insert(1, "module Autogenerated")
|
70
|
+
op_test << "end"
|
71
|
+
|
72
|
+
File.write "test/docs/autogenerated/operation_" + File.basename(filepath), op_test.join("")
|
73
|
+
end
|
74
|
+
|
75
|
+
end # ConvertOperationTest
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "trailblazer/core/utils/convert_operation_test"
|
2
|
+
require "trailblazer/core/utils/symbol_inspect_for"
|
3
|
+
|
4
|
+
module Trailblazer
|
5
|
+
module Core
|
6
|
+
# def self.convert_operation_test(*args, **kws)
|
7
|
+
# Utils::ConvertOperationTest.(*args, **kws)
|
8
|
+
# end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
extend Forwardable
|
12
|
+
def_delegator Utils::ConvertOperationTest, :call, :convert_operation_test
|
13
|
+
def_delegator Utils, :symbol_inspect_for
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trailblazer-core-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Sutterer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- apotonick@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- Gemfile
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/trailblazer/core.rb
|
25
|
+
- lib/trailblazer/core/utils.rb
|
26
|
+
- lib/trailblazer/core/utils/convert_operation_test.rb
|
27
|
+
- lib/trailblazer/core/utils/symbol_inspect_for.rb
|
28
|
+
- lib/trailblazer/core/utils/version.rb
|
29
|
+
- sig/trailblazer/core/utils.rbs
|
30
|
+
homepage: https://trailblazer.to
|
31
|
+
licenses: []
|
32
|
+
metadata:
|
33
|
+
homepage_uri: https://trailblazer.to
|
34
|
+
source_code_uri: https://github.com/trailblazer/trailblazer-core-utils
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.5.0
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.2.3
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Utilities for Trailblazer core developers.
|
54
|
+
test_files: []
|