trailblazer-core-utils 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62598df4c51f4076a1dfdc07a2feb47e0aff662240824a96f9c18351cc457936
4
- data.tar.gz: 4d0682cc676aefb7f823228c6f83c2b625e96fb89a7e32dc7aaae6c076aa7993
3
+ metadata.gz: 275a1cdc26964260f5ee4cf9fb3b7a29b11529284991424f362ea2458c6981f0
4
+ data.tar.gz: 40c2da81a31c35a032c3cda8864e3814d3c8097d885a7036d6ed20e2e3c18090
5
5
  SHA512:
6
- metadata.gz: 1058864d83d855a99ce737e6106af66ba1715eb98f498589e3a4a2da2f3b12c2b787d16e6b62308f7e9eb4bc0f179a619d77b562b715aeb55ced99d4cf5deffb
7
- data.tar.gz: cc64ef23d77f6c902aab00cd39527ef17146ba8cc244480640f75e29d52812759ddb1d4f354670f76cedf3e17cd9c4e780d33dd235156d3c2839c7b06911e28a
6
+ metadata.gz: f6a3c8fbd5f39a5a354e669473e60b1b14059f6846237def36d5eb9e7b8d2941602b473038225dbf95bb8540850e7ca6e581bbf36835a3c587876bbe9b4ff928
7
+ data.tar.gz: 6a536400f0d83044a6fc641cb1f787b2e5be2928e6d1bda147ab56915804ef1ce9e4da3346c4a7c7602d89dc543e06e814505a58800f63f989f8102425bfcdd3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.0.3]
2
+
3
+ * Introduce `Utils.inspect` to cover `Hash#inspect` tests across all Rubies, including 3.4.
4
+ * Introduce `:source_gem` and `:target`.
5
+ Todo: ADD TEST/DOCS/AUTOGENERATED automatically
6
+
1
7
  ## [0.0.2]
2
8
 
3
9
  * Require `forwardable`.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require "rake/testtask"
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "test"
8
8
  t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
9
+ t.test_files = FileList["test/*_test.rb"]
10
10
  end
11
11
 
12
12
  task default: :test
@@ -2,15 +2,17 @@ module Trailblazer
2
2
  module Core
3
3
  module Utils
4
4
  # Convert an Activity test into an operation test.
5
- # Store at {test/docs/autogenerated/operation_model_test.rb}
5
+ # Store at {:target}
6
6
  #
7
7
  # {#~ctx_to_result} allows to always convert ctx to result within the block.
8
8
 
9
+ # TODO: add {skip}
9
10
  module ConvertOperationTest
10
- def self.call(filepath)
11
+ def self.call(filepath, target:, source_gem:)
11
12
  within_marker = false
12
13
  within_ignore = false
13
14
  within_ctx_to_result = false
15
+ within_keep = false
14
16
 
15
17
  op_test =
16
18
  File.foreach(filepath).collect do |line|
@@ -21,7 +23,14 @@ module Trailblazer
21
23
  within_marker = false
22
24
  end
23
25
 
24
- if line.match(/#~ignore/) # FIXME: we don't use this!
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/)
25
34
  within_ignore = true
26
35
  end
27
36
  if line.match(/#~ignore end/)
@@ -38,9 +47,17 @@ module Trailblazer
38
47
  if within_ignore
39
48
  # puts "@@@@@ #{line.inspect}"
40
49
  line = ""
50
+ elsif within_keep
51
+ line
41
52
  else
42
- line = line.sub("< Trailblazer::Activity::Railway", "< Trailblazer::Operation")
43
- line = line.gsub("::Activity", "::Operation")
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")
44
61
 
45
62
  # if within_marker
46
63
  line = line.sub("signal, (ctx, _) =", "result =")
@@ -57,6 +74,7 @@ module Trailblazer
57
74
  semantic = match[2]
58
75
  line = "#{match[1]}result.success? # => #{semantic == ":success" ? true : false}\n"
59
76
  end
77
+ end
60
78
  # end
61
79
 
62
80
  line = line.sub("assert_equal ctx", "assert_equal result")
@@ -66,10 +84,9 @@ module Trailblazer
66
84
  line
67
85
  end
68
86
 
69
- op_test.insert(1, "module Autogenerated")
70
- op_test << "end"
87
+ op_test.insert(0, "# THIS FILE IS AUTOGENERATED FROM #{source_gem}/#{filepath}\n")
71
88
 
72
- File.write "test/docs/autogenerated/operation_" + File.basename(filepath), op_test.join("")
89
+ File.write target, op_test.join("")
73
90
  end
74
91
 
75
92
  end # ConvertOperationTest
@@ -0,0 +1,24 @@
1
+ module Trailblazer
2
+ module Core
3
+ module Utils
4
+ def self.inspect(object)
5
+ return object.inspect unless object.is_a?(Hash)
6
+
7
+ old_string = object.inspect
8
+ # old_string = %({{symbol: 1, "string" => 2},"string" => 1})
9
+
10
+ new_string = old_string.gsub(/([{ ])(\w+): /, '\1:\2=>')
11
+ new_string = new_string.gsub(" => ", "=>")
12
+
13
+ return new_string
14
+ "asdfafasdff"
15
+
16
+ # if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7.0") || RUBY_ENGINE == 'jruby'
17
+ # "#{name}"
18
+ # else
19
+ # ":#{name}"
20
+ # end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,7 +1,7 @@
1
1
  module Trailblazer
2
2
  module Core
3
3
  module Utils
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  require "forwardable"
2
2
  require "trailblazer/core/utils/convert_operation_test"
3
3
  require "trailblazer/core/utils/symbol_inspect_for"
4
+ require "trailblazer/core/utils/inspect"
4
5
 
5
6
  module Trailblazer
6
7
  module Core
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-core-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-13 00:00:00.000000000 Z
11
+ date: 2024-11-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -24,9 +24,9 @@ files:
24
24
  - lib/trailblazer/core.rb
25
25
  - lib/trailblazer/core/utils.rb
26
26
  - lib/trailblazer/core/utils/convert_operation_test.rb
27
+ - lib/trailblazer/core/utils/inspect.rb
27
28
  - lib/trailblazer/core/utils/symbol_inspect_for.rb
28
29
  - lib/trailblazer/core/utils/version.rb
29
- - sig/trailblazer/core/utils.rbs
30
30
  homepage: https://trailblazer.to
31
31
  licenses: []
32
32
  metadata:
@@ -1,8 +0,0 @@
1
- module Trailblazer
2
- module Core
3
- module Utils
4
- VERSION: String
5
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
- end
7
- end
8
- end