karafka-core 2.5.8 → 2.5.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +40 -27
  3. data/.github/workflows/push.yml +2 -2
  4. data/.github/workflows/verify-action-pins.yml +1 -1
  5. data/.gitignore +0 -1
  6. data/.rubocop.yml +37 -0
  7. data/.ruby-version +1 -1
  8. data/.yard-lint.yml +173 -72
  9. data/CHANGELOG.md +8 -0
  10. data/Gemfile +5 -6
  11. data/Gemfile.lint +13 -0
  12. data/Gemfile.lint.lock +103 -0
  13. data/Gemfile.lock +12 -23
  14. data/Rakefile +14 -2
  15. data/karafka-core.gemspec +21 -21
  16. data/lib/karafka/core/configurable/node.rb +39 -39
  17. data/lib/karafka/core/configurable.rb +4 -4
  18. data/lib/karafka/core/contractable/contract.rb +2 -2
  19. data/lib/karafka/core/contractable/result.rb +10 -10
  20. data/lib/karafka/core/helpers/minitest_locator.rb +101 -0
  21. data/lib/karafka/core/helpers/rspec_locator.rb +9 -9
  22. data/lib/karafka/core/helpers/time.rb +1 -1
  23. data/lib/karafka/core/monitoring/monitor.rb +1 -1
  24. data/lib/karafka/core/monitoring/notifications.rb +2 -2
  25. data/lib/karafka/core/monitoring/statistics_decorator.rb +69 -62
  26. data/lib/karafka/core/version.rb +1 -1
  27. data/lib/karafka/core.rb +1 -1
  28. data/lib/karafka-core.rb +22 -22
  29. data/package-lock.json +331 -0
  30. data/package.json +9 -0
  31. data/renovate.json +28 -6
  32. data/test/lib/karafka/core/configurable/leaf_test.rb +3 -0
  33. data/test/lib/karafka/core/configurable/node_test.rb +3 -0
  34. data/test/lib/karafka/core/configurable_test.rb +504 -0
  35. data/test/lib/karafka/core/contractable/contract_test.rb +241 -0
  36. data/test/lib/karafka/core/contractable/result_test.rb +106 -0
  37. data/test/lib/karafka/core/contractable/rule_test.rb +5 -0
  38. data/test/lib/karafka/core/contractable_test.rb +3 -0
  39. data/test/lib/karafka/core/helpers/time_test.rb +29 -0
  40. data/test/lib/karafka/core/instrumentation/callbacks_manager_test.rb +81 -0
  41. data/test/lib/karafka/core/instrumentation_test.rb +35 -0
  42. data/test/lib/karafka/core/monitoring/event_test.rb +25 -0
  43. data/test/lib/karafka/core/monitoring/monitor_test.rb +237 -0
  44. data/test/lib/karafka/core/monitoring/notifications_test.rb +275 -0
  45. data/test/lib/karafka/core/monitoring/statistics_decorator_test.rb +284 -0
  46. data/test/lib/karafka/core/monitoring_test.rb +3 -0
  47. data/test/lib/karafka/core/patches/rdkafka/bindings_test.rb +25 -0
  48. data/test/lib/karafka/core/taggable/tags_test.rb +66 -0
  49. data/test/lib/karafka/core/taggable_test.rb +36 -0
  50. data/test/lib/karafka/core/version_test.rb +5 -0
  51. data/test/lib/karafka/core_test.rb +13 -0
  52. data/test/lib/karafka-core_test.rb +3 -0
  53. data/test/support/class_builder.rb +24 -0
  54. data/test/support/describe_current_helper.rb +41 -0
  55. data/test/test_helper.rb +55 -0
  56. metadata +32 -4
  57. data/.coditsu/ci.yml +0 -3
  58. data/.rspec +0 -1
data/Gemfile.lint.lock ADDED
@@ -0,0 +1,103 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ast (2.4.3)
5
+ json (2.18.0)
6
+ language_server-protocol (3.17.0.5)
7
+ lint_roller (1.1.0)
8
+ parallel (1.27.0)
9
+ parser (3.3.10.1)
10
+ ast (~> 2.4.1)
11
+ racc
12
+ prism (1.8.0)
13
+ racc (1.8.1)
14
+ rainbow (3.1.1)
15
+ regexp_parser (2.11.3)
16
+ rubocop (1.82.1)
17
+ json (~> 2.3)
18
+ language_server-protocol (~> 3.17.0.2)
19
+ lint_roller (~> 1.1.0)
20
+ parallel (~> 1.10)
21
+ parser (>= 3.3.0.2)
22
+ rainbow (>= 2.2.2, < 4.0)
23
+ regexp_parser (>= 2.9.3, < 3.0)
24
+ rubocop-ast (>= 1.48.0, < 2.0)
25
+ ruby-progressbar (~> 1.7)
26
+ unicode-display_width (>= 2.4.0, < 4.0)
27
+ rubocop-ast (1.49.0)
28
+ parser (>= 3.3.7.2)
29
+ prism (~> 1.7)
30
+ rubocop-minitest (0.39.1)
31
+ lint_roller (~> 1.1)
32
+ rubocop (>= 1.75.0, < 2.0)
33
+ rubocop-ast (>= 1.38.0, < 2.0)
34
+ rubocop-performance (1.26.1)
35
+ lint_roller (~> 1.1)
36
+ rubocop (>= 1.75.0, < 2.0)
37
+ rubocop-ast (>= 1.47.1, < 2.0)
38
+ rubocop-thread_safety (0.7.3)
39
+ lint_roller (~> 1.1)
40
+ rubocop (~> 1.72, >= 1.72.1)
41
+ rubocop-ast (>= 1.44.0, < 2.0)
42
+ ruby-progressbar (1.13.0)
43
+ standard (1.53.0)
44
+ language_server-protocol (~> 3.17.0.2)
45
+ lint_roller (~> 1.0)
46
+ rubocop (~> 1.82.0)
47
+ standard-custom (~> 1.0.0)
48
+ standard-performance (~> 1.8)
49
+ standard-custom (1.0.2)
50
+ lint_roller (~> 1.0)
51
+ rubocop (~> 1.50)
52
+ standard-performance (1.9.0)
53
+ lint_roller (~> 1.1)
54
+ rubocop-performance (~> 1.26.0)
55
+ unicode-display_width (3.2.0)
56
+ unicode-emoji (~> 4.1)
57
+ unicode-emoji (4.2.0)
58
+ yard (0.9.38)
59
+ yard-lint (1.4.0)
60
+ yard (~> 0.9)
61
+ zeitwerk (~> 2.6)
62
+ zeitwerk (2.7.4)
63
+
64
+ PLATFORMS
65
+ ruby
66
+ x86_64-linux
67
+
68
+ DEPENDENCIES
69
+ rubocop-minitest
70
+ rubocop-performance
71
+ rubocop-thread_safety
72
+ standard
73
+ standard-performance
74
+ yard-lint
75
+
76
+ CHECKSUMS
77
+ ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
78
+ json (2.18.0) sha256=b10506aee4183f5cf49e0efc48073d7b75843ce3782c68dbeb763351c08fd505
79
+ language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
80
+ lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
81
+ parallel (1.27.0) sha256=4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130
82
+ parser (3.3.10.1) sha256=06f6a725d2cd91e5e7f2b7c32ba143631e1f7c8ae2fb918fc4cebec187e6a688
83
+ prism (1.8.0) sha256=84453a16ef5530ea62c5f03ec16b52a459575ad4e7b9c2b360fd8ce2c39c1254
84
+ racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
85
+ rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
86
+ regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
87
+ rubocop (1.82.1) sha256=09f1a6a654a960eda767aebea33e47603080f8e9c9a3f019bf9b94c9cab5e273
88
+ rubocop-ast (1.49.0) sha256=49c3676d3123a0923d333e20c6c2dbaaae2d2287b475273fddee0c61da9f71fd
89
+ rubocop-minitest (0.39.1) sha256=998398d6da4026d297f0f9bf709a1eac5f2b6947c24431f94af08138510cf7ed
90
+ rubocop-performance (1.26.1) sha256=cd19b936ff196df85829d264b522fd4f98b6c89ad271fa52744a8c11b8f71834
91
+ rubocop-thread_safety (0.7.3) sha256=067cdd52fbf5deffc18995437e45b5194236eaff4f71de3375a1f6052e48f431
92
+ ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
93
+ standard (1.53.0) sha256=f3c9493385db7079d0abce6f7582f553122156997b81258cd361d3480eeacf9c
94
+ standard-custom (1.0.2) sha256=424adc84179a074f1a2a309bb9cf7cd6bfdb2b6541f20c6bf9436c0ba22a652b
95
+ standard-performance (1.9.0) sha256=49483d31be448292951d80e5e67cdcb576c2502103c7b40aec6f1b6e9c88e3f2
96
+ unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
97
+ unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
98
+ yard (0.9.38) sha256=721fb82afb10532aa49860655f6cc2eaa7130889df291b052e1e6b268283010f
99
+ yard-lint (1.4.0) sha256=7dd88fbb08fd77cb840bea899d58812817b36d92291b5693dd0eeb3af9f91f0f
100
+ zeitwerk (2.7.4) sha256=2bef90f356bdafe9a6c2bd32bcd804f83a4f9b8bc27f3600fff051eb3edcec8b
101
+
102
+ BUNDLED WITH
103
+ 4.0.3
data/Gemfile.lock CHANGED
@@ -1,16 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-core (2.5.8)
4
+ karafka-core (2.5.10)
5
5
  karafka-rdkafka (>= 0.20.0)
6
6
  logger (>= 1.6.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- byebug (12.0.0)
12
- diff-lcs (1.6.2)
11
+ byebug (13.0.0)
12
+ reline (>= 0.6.0)
13
13
  docile (1.4.1)
14
+ drb (2.2.3)
14
15
  ffi (1.17.2)
15
16
  ffi (1.17.2-aarch64-linux-gnu)
16
17
  ffi (1.17.2-aarch64-linux-musl)
@@ -22,6 +23,7 @@ GEM
22
23
  ffi (1.17.2-x86_64-darwin)
23
24
  ffi (1.17.2-x86_64-linux-gnu)
24
25
  ffi (1.17.2-x86_64-linux-musl)
26
+ io-console (0.8.2)
25
27
  json (2.15.1)
26
28
  karafka-rdkafka (0.22.2)
27
29
  ffi (~> 1.15)
@@ -55,20 +57,13 @@ GEM
55
57
  rake (> 12)
56
58
  logger (1.7.0)
57
59
  mini_portile2 (2.8.9)
60
+ minitest (6.0.2)
61
+ drb (~> 2.0)
62
+ prism (~> 1.5)
63
+ prism (1.9.0)
58
64
  rake (13.3.0)
59
- rspec (3.13.2)
60
- rspec-core (~> 3.13.0)
61
- rspec-expectations (~> 3.13.0)
62
- rspec-mocks (~> 3.13.0)
63
- rspec-core (3.13.6)
64
- rspec-support (~> 3.13.0)
65
- rspec-expectations (3.13.5)
66
- diff-lcs (>= 1.2.0, < 2.0)
67
- rspec-support (~> 3.13.0)
68
- rspec-mocks (3.13.6)
69
- diff-lcs (>= 1.2.0, < 2.0)
70
- rspec-support (~> 3.13.0)
71
- rspec-support (3.13.6)
65
+ reline (0.6.3)
66
+ io-console (~> 0.5)
72
67
  simplecov (0.22.0)
73
68
  docile (~> 1.1)
74
69
  simplecov-html (~> 0.11)
@@ -76,11 +71,6 @@ GEM
76
71
  simplecov-html (0.13.2)
77
72
  simplecov_json_formatter (0.1.4)
78
73
  warning (1.5.0)
79
- yard (0.9.37)
80
- yard-lint (1.2.3)
81
- yard (~> 0.9)
82
- zeitwerk (~> 2.6)
83
- zeitwerk (2.7.3)
84
74
 
85
75
  PLATFORMS
86
76
  aarch64-linux-gnu
@@ -98,10 +88,9 @@ PLATFORMS
98
88
  DEPENDENCIES
99
89
  byebug
100
90
  karafka-core!
101
- rspec
91
+ minitest
102
92
  simplecov
103
93
  warning
104
- yard-lint
105
94
 
106
95
  BUNDLED WITH
107
96
  2.6.9
data/Rakefile CHANGED
@@ -1,4 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/setup'
4
- require 'bundler/gem_tasks'
3
+ require "bundler/setup"
4
+ require "bundler/gem_tasks"
5
+
6
+ require "minitest/test_task"
7
+
8
+ Minitest::TestTask.create(:test) do |t|
9
+ t.libs << "test"
10
+ t.libs << "lib"
11
+ t.warning = false
12
+ t.test_prelude = 'require "test_helper"'
13
+ t.test_globs = ["test/**/*_test.rb"]
14
+ end
15
+
16
+ task default: :test
data/karafka-core.gemspec CHANGED
@@ -1,35 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
- require 'karafka/core/version'
6
+ require "karafka/core/version"
7
7
 
8
8
  Gem::Specification.new do |spec|
9
- spec.name = 'karafka-core'
10
- spec.version = Karafka::Core::VERSION
11
- spec.platform = Gem::Platform::RUBY
12
- spec.authors = ['Maciej Mensfeld']
13
- spec.email = %w[contact@karafka.io]
14
- spec.homepage = 'https://karafka.io'
15
- spec.summary = 'Karafka ecosystem core modules'
16
- spec.description = 'A toolset of small support modules used throughout the Karafka ecosystem'
17
- spec.licenses = %w[MIT]
9
+ spec.name = "karafka-core"
10
+ spec.version = Karafka::Core::VERSION
11
+ spec.platform = Gem::Platform::RUBY
12
+ spec.authors = ["Maciej Mensfeld"]
13
+ spec.email = %w[contact@karafka.io]
14
+ spec.homepage = "https://karafka.io"
15
+ spec.summary = "Karafka ecosystem core modules"
16
+ spec.description = "A toolset of small support modules used throughout the Karafka ecosystem"
17
+ spec.licenses = %w[MIT]
18
18
 
19
- spec.add_dependency 'karafka-rdkafka', '>= 0.20.0'
20
- spec.add_dependency 'logger', '>= 1.6.0'
19
+ spec.add_dependency "karafka-rdkafka", ">= 0.20.0"
20
+ spec.add_dependency "logger", ">= 1.6.0"
21
21
 
22
- spec.required_ruby_version = '>= 3.2.0'
22
+ spec.required_ruby_version = ">= 3.2.0"
23
23
 
24
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
25
25
  spec.require_paths = %w[lib]
26
26
 
27
27
  spec.metadata = {
28
- 'homepage_uri' => 'https://karafka.io',
29
- 'changelog_uri' => 'https://karafka.io/docs/Changelog-Karafka-Core',
30
- 'bug_tracker_uri' => 'https://github.com/karafka/karafka-core/issues',
31
- 'source_code_uri' => 'https://github.com/karafka/karafka-core',
32
- 'documentation_uri' => 'https://karafka.io/docs',
33
- 'rubygems_mfa_required' => 'true'
28
+ "homepage_uri" => "https://karafka.io",
29
+ "changelog_uri" => "https://karafka.io/docs/Changelog-Karafka-Core",
30
+ "bug_tracker_uri" => "https://github.com/karafka/karafka-core/issues",
31
+ "source_code_uri" => "https://github.com/karafka/karafka-core",
32
+ "documentation_uri" => "https://karafka.io/docs",
33
+ "rubygems_mfa_required" => "true"
34
34
  }
35
35
  end
@@ -36,10 +36,10 @@ module Karafka
36
36
  # @param block [Proc] block for nested settings
37
37
  def setting(node_name, default: nil, constructor: nil, lazy: false, &block)
38
38
  @children << if block
39
- Node.new(node_name, block)
40
- else
41
- Leaf.new(node_name, default, constructor, false, lazy)
42
- end
39
+ Node.new(node_name, block)
40
+ else
41
+ Leaf.new(node_name, default, constructor, false, lazy)
42
+ end
43
43
 
44
44
  compile
45
45
  end
@@ -60,20 +60,20 @@ module Karafka
60
60
 
61
61
  @children.each do |value|
62
62
  config[value.node_name] = if value.is_a?(Leaf)
63
- result = if @configs_refs.key?(value.node_name)
64
- @configs_refs[value.node_name]
65
- elsif value.constructor
66
- value.constructor.call
67
- elsif value.default
68
- value.default
69
- end
70
-
71
- # We need to check if value is not a result node for cases
72
- # where we merge additional config
73
- result.is_a?(Node) ? result.to_h : result
74
- else
75
- value.to_h
76
- end
63
+ result = if @configs_refs.key?(value.node_name)
64
+ @configs_refs[value.node_name]
65
+ elsif value.constructor
66
+ value.constructor.call
67
+ elsif value.default
68
+ value.default
69
+ end
70
+
71
+ # We need to check if value is not a result node for cases
72
+ # where we merge additional config
73
+ result.is_a?(Node) ? result.to_h : result
74
+ else
75
+ value.to_h
76
+ end
77
77
  end
78
78
 
79
79
  config.freeze
@@ -87,14 +87,14 @@ module Karafka
87
87
 
88
88
  children.each do |value|
89
89
  dupped.children << if value.is_a?(Leaf)
90
- # After inheritance we need to reload the state so the leafs are
91
- # recompiled again
92
- value = value.dup
93
- value.compiled = false
94
- value
95
- else
96
- value.deep_dup
97
- end
90
+ # After inheritance we need to reload the state so the leafs are
91
+ # recompiled again
92
+ value = value.dup
93
+ value.compiled = false
94
+ value
95
+ else
96
+ value.deep_dup
97
+ end
98
98
  end
99
99
 
100
100
  dupped
@@ -116,19 +116,19 @@ module Karafka
116
116
  next if skippable
117
117
 
118
118
  initialized = if value.is_a?(Leaf)
119
- value.compiled = true
120
-
121
- if value.constructor && value.lazy?
122
- false
123
- elsif value.constructor
124
- call_constructor(value)
125
- else
126
- value.default
127
- end
128
- else
129
- value.compile
130
- value
131
- end
119
+ value.compiled = true
120
+
121
+ if value.constructor && value.lazy?
122
+ false
123
+ elsif value.constructor
124
+ call_constructor(value)
125
+ else
126
+ value.default
127
+ end
128
+ else
129
+ value.compile
130
+ value
131
+ end
132
132
 
133
133
  if lazy_leaf && !initialized
134
134
  build_dynamic_accessor(value)
@@ -50,10 +50,10 @@ module Karafka
50
50
 
51
51
  # This will handle inheritance
52
52
  @config = if superclass.respond_to?(:config)
53
- superclass.config.deep_dup
54
- else
55
- Node.new(:root)
56
- end
53
+ superclass.config.deep_dup
54
+ else
55
+ Node.new(:root)
56
+ end
57
57
  end
58
58
 
59
59
  # Allows for a per class configuration (if needed)
@@ -126,7 +126,7 @@ module Karafka
126
126
 
127
127
  # We need to compare `DIG_MISS` against stuff because of the ownership of the `#==`
128
128
  # method
129
- if DIG_MISS == for_checking
129
+ if for_checking == DIG_MISS
130
130
  errors << [scope + rule.path, :missing]
131
131
  else
132
132
  result = rule.validator.call(for_checking, data, errors, self)
@@ -147,7 +147,7 @@ module Karafka
147
147
  def validate_optional(data, rule, errors, scope)
148
148
  for_checking = dig(data, rule.path)
149
149
 
150
- return if DIG_MISS == for_checking
150
+ return if for_checking == DIG_MISS
151
151
 
152
152
  result = rule.validator.call(for_checking, data, errors, self)
153
153
 
@@ -26,14 +26,14 @@ module Karafka
26
26
  hashed = {}
27
27
 
28
28
  errors.each do |error|
29
- scope = error.first.map(&:to_s).join('.').to_sym
29
+ scope = error.first.map(&:to_s).join(".").to_sym
30
30
 
31
31
  # This will allow for usage of custom messages instead of yaml keys if needed
32
32
  hashed[scope] = if error.last.is_a?(String)
33
- error.last
34
- else
35
- build_message(contract, scope, error.last)
36
- end
33
+ error.last
34
+ else
35
+ build_message(contract, scope, error.last)
36
+ end
37
37
  end
38
38
 
39
39
  @errors = hashed
@@ -56,7 +56,7 @@ module Karafka
56
56
  messages = contract.class.config.error_messages
57
57
 
58
58
  # Split scope into parts for progressive checking
59
- scope_parts = scope.to_s.split('.')
59
+ scope_parts = scope.to_s.split(".")
60
60
 
61
61
  # Try full scope first, then progressively remove from beginning
62
62
  # This allows us to have full path scoped errors but can also be used as a fallback,
@@ -65,10 +65,10 @@ module Karafka
65
65
  current_scope_parts = scope_parts[i..]
66
66
 
67
67
  key = if current_scope_parts.empty?
68
- error_key.to_s
69
- else
70
- "#{current_scope_parts.join('.')}_#{error_key}"
71
- end
68
+ error_key.to_s
69
+ else
70
+ "#{current_scope_parts.join(".")}_#{error_key}"
71
+ end
72
72
 
73
73
  return messages[key] if messages.key?(key)
74
74
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Core
5
+ module Helpers
6
+ # Minitest/spec extension for the subject class auto-discovery.
7
+ # It automatically detects the class name that should be described in the given test
8
+ # based on the test file path.
9
+ # @example Extend with instantiation and use `describe_current`
10
+ # extend Karafka::Core::Helpers::MinitestLocator.new(__FILE__)
11
+ class MinitestLocator < Module
12
+ # @param test_helper_file_path [String] path to the test_helper.rb file
13
+ # @param inflections [Hash{String => String}] optional inflections map
14
+ def initialize(test_helper_file_path, inflections = {})
15
+ super()
16
+ @inflections = inflections
17
+ @tests_root_dir = ::File.dirname(test_helper_file_path)
18
+ end
19
+
20
+ # Builds needed API
21
+ # @param minitest_module [Module] module or main object to extend
22
+ def extended(minitest_module)
23
+ super
24
+ this = self
25
+ # Allows "auto subject" definitions for the `describe` method, as it will figure
26
+ # out the proper class that we want to describe
27
+ # @param block [Proc] block with tests
28
+ minitest_module.define_singleton_method :describe_current do |&block|
29
+ describe(this.inherited, &block)
30
+ end
31
+ end
32
+
33
+ # @return [Class] class name for the minitest `describe` method
34
+ def inherited
35
+ caller(2..2)
36
+ .first
37
+ .split(":")
38
+ .first
39
+ .gsub(@tests_root_dir, "")
40
+ .gsub("_test.rb", "")
41
+ .split("/")
42
+ .delete_if(&:empty?)
43
+ .itself[1..]
44
+ .join("/")
45
+ .then { |path| custom_camelize(path) }
46
+ .then { |string| transform_inflections(string) }
47
+ .then { |class_name| custom_constantize(class_name) }
48
+ end
49
+
50
+ private
51
+
52
+ # @param string [String] string we want to cast
53
+ # @return [String] string after inflections
54
+ def transform_inflections(string)
55
+ string = string.dup
56
+ @inflections.each { |from, to| string.gsub!(from, to) }
57
+ string
58
+ end
59
+
60
+ # Custom implementation of camelize without ActiveSupport
61
+ # @param string [String] underscored string to convert to CamelCase
62
+ # @return [String] camel-case string
63
+ def custom_camelize(string)
64
+ # First, replace slashes with :: for proper namespacing
65
+ string = string.gsub("/", "::")
66
+
67
+ # Then camelize each segment
68
+ string.gsub(/(?:^|_|::)([a-z])/) do |match|
69
+ # If it's a namespace separator, keep it and uppercase the following letter
70
+ if match.include?("::")
71
+ "::#{match[-1].upcase}"
72
+ else
73
+ match[-1].upcase
74
+ end
75
+ end
76
+ end
77
+
78
+ # Custom implementation of constantize without ActiveSupport
79
+ # @param string [String] string representing a constant name
80
+ # @return [Class, Module] the constant
81
+ def custom_constantize(string)
82
+ names = string.split("::")
83
+ constant = Object
84
+ regexp = /^[A-Z][a-zA-Z0-9_]*$/
85
+
86
+ names.each do |name|
87
+ # Make sure we're dealing with a valid constant name
88
+ raise NameError, "#{name} is not a valid constant name!" unless name.match?(regexp)
89
+
90
+ # Get the constant from its parent
91
+ constant = constant.const_get(name)
92
+ end
93
+
94
+ constant
95
+ rescue NameError => e
96
+ raise NameError, "Uninitialized constant #{string}: #{e.message}"
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fileutils'
3
+ require "fileutils"
4
4
 
5
5
  module Karafka
6
6
  module Core
@@ -37,14 +37,14 @@ module Karafka
37
37
  def inherited
38
38
  caller(2..2)
39
39
  .first
40
- .split(':')
40
+ .split(":")
41
41
  .first
42
- .gsub(@specs_root_dir, '')
43
- .gsub('_spec.rb', '')
44
- .split('/')
42
+ .gsub(@specs_root_dir, "")
43
+ .gsub("_spec.rb", "")
44
+ .split("/")
45
45
  .delete_if(&:empty?)
46
46
  .itself[1..]
47
- .join('/')
47
+ .join("/")
48
48
  .then { |path| custom_camelize(path) }
49
49
  .then { |string| transform_inflections(string) }
50
50
  .then { |class_name| custom_constantize(class_name) }
@@ -65,12 +65,12 @@ module Karafka
65
65
  # @return [String] camel-case string
66
66
  def custom_camelize(string)
67
67
  # First, replace slashes with :: for proper namespacing
68
- string = string.gsub('/', '::')
68
+ string = string.gsub("/", "::")
69
69
 
70
70
  # Then camelize each segment
71
71
  string.gsub(/(?:^|_|::)([a-z])/) do |match|
72
72
  # If it's a namespace separator, keep it and uppercase the following letter
73
- if match.include?('::')
73
+ if match.include?("::")
74
74
  "::#{match[-1].upcase}"
75
75
  else
76
76
  match[-1].upcase
@@ -82,7 +82,7 @@ module Karafka
82
82
  # @param string [String] string representing a constant name
83
83
  # @return [Class, Module] the constant
84
84
  def custom_constantize(string)
85
- names = string.split('::')
85
+ names = string.split("::")
86
86
  constant = Object
87
87
  regexp = /^[A-Z][a-zA-Z0-9_]*$/
88
88
 
@@ -6,7 +6,7 @@ module Karafka
6
6
  module Helpers
7
7
  # Time related methods used across Karafka
8
8
  module Time
9
- if RUBY_VERSION >= '3.2'
9
+ if RUBY_VERSION >= "3.2"
10
10
  # @return [Float] current monotonic time in milliseconds
11
11
  def monotonic_now
12
12
  ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :float_millisecond)
@@ -28,7 +28,7 @@ module Karafka
28
28
  # @param event_id [String, Symbol] event id
29
29
  # @param payload [Hash]
30
30
  def instrument(event_id, payload = EMPTY_HASH, &)
31
- full_event_name = @mapped_events[event_id] ||= [event_id, @namespace].compact.join('.')
31
+ full_event_name = @mapped_events[event_id] ||= [event_id, @namespace].compact.join(".")
32
32
 
33
33
  @notifications_bus.instrument(full_event_name, payload, &)
34
34
  end
@@ -39,7 +39,7 @@ module Karafka
39
39
  def register_event(event_id)
40
40
  @mutex.synchronize do
41
41
  @listeners[event_id] = []
42
- @events_methods_map[event_id] = :"on_#{event_id.to_s.tr('.', '_')}"
42
+ @events_methods_map[event_id] = :"on_#{event_id.to_s.tr(".", "_")}"
43
43
  end
44
44
  end
45
45
 
@@ -161,7 +161,7 @@ module Karafka
161
161
 
162
162
  # Notifies all assigned listeners about the event
163
163
  # @param event_id [String]
164
- # @param event [Event] event object
164
+ # @param event [Event] event with payload to broadcast to listeners
165
165
  # @param assigned_listeners [Array] list of listeners to notify
166
166
  def notify_listeners(event_id, event, assigned_listeners)
167
167
  assigned_listeners.each do |listener|