karafka-core 2.5.9 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f40905132baef109ff513aedd80d0be8aa041a4bc44117e2e897e554daa9b47c
4
- data.tar.gz: d4fbaeb025d4f79d834aea13f4defd294f7d874c628973ce5279b840b713d006
3
+ metadata.gz: fe7a4974267a2a3b2b200e0763a13042d98695c0586931d00d0016087bc5dfe2
4
+ data.tar.gz: a5bdd9235a999028ad120d79c2986e05986ee1b9df8a5de6b813fff634bc5619
5
5
  SHA512:
6
- metadata.gz: 8ae8c3a4772bb914737111319cab6706a45a6af62826a16cb357d43a7521f0b390e2ab338e2e818c24c738d586d1feb89c18799b055d83ce4f089b9642c36910
7
- data.tar.gz: fbeaeac510a0b2ad3ef23cca8d5a5b958a9e6debbe98899fb4590f3a1dbccaec7543fbd58dea66b5cd344a7783b051d4d60398ba370e66d8fb07a2244ad454d0
6
+ metadata.gz: be10ba6481782906bbb076ea69ab9aa05c80f4c295ce82c2faacc53ee27a8ebd01e4c7a200088205058fda7e7efef494d71ac96492d3cf074f579ea331597148
7
+ data.tar.gz: a51a53327518e282ab42461fccc3aea78407de1418d97376a64b25dda687b616a54f0c6639b542d0c104534876b1c34d9f7f1434486300c40708f129f03ad267
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Karafka Core Changelog
2
2
 
3
+ ## 2.5.10 (2026-03-02)
4
+ - [Enhancement] Introduce `MinitestLocator` helper for minitest/spec subject class auto-discovery from test file paths.
5
+
3
6
  ## 2.5.9 (2026-03-02)
4
7
  - [Enhancement] Optimize `StatisticsDecorator` to eliminate per-hash Array allocations by using `each_pair` with a per-call pending-writes buffer instead of `current.keys.each`, reducing allocations from tens of thousands to one per call at scale.
5
8
  - [Enhancement] Inline `StatisticsDecorator#append` and `#suffix_keys_for` into `#diff` to reduce method call overhead by ~96% (from ~915k to ~39k calls at 6400 partitions).
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-core (2.5.9)
4
+ karafka-core (2.5.10)
5
5
  karafka-rdkafka (>= 0.20.0)
6
6
  logger (>= 1.6.0)
7
7
 
@@ -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
@@ -4,6 +4,6 @@ module Karafka
4
4
  module Core
5
5
  # Current Karafka::Core version
6
6
  # We follow the versioning schema of given Karafka version
7
- VERSION = "2.5.9"
7
+ VERSION = "2.5.10"
8
8
  end
9
9
  end
@@ -4,55 +4,11 @@
4
4
  # Provides `describe_current` that auto-discovers the class under test from file path,
5
5
  # `described_class` and `subject` DSL methods.
6
6
 
7
- TESTS_ROOT_DIR = File.expand_path("..", __dir__)
7
+ require "karafka/core/helpers/minitest_locator"
8
8
 
9
- # Top-level method: auto-discovers the class from the caller file path and opens a describe block
10
- def describe_current(&block)
11
- klass = caller(1..1)
12
- .first
13
- .split(":")
14
- .first
15
- .gsub(TESTS_ROOT_DIR, "")
16
- .gsub("_test.rb", "")
17
- .split("/")
18
- .delete_if(&:empty?)
19
- .itself[1..]
20
- .join("/")
21
- .then { |path| custom_camelize(path) }
22
- .then { |class_name| custom_constantize(class_name) }
23
-
24
- describe(klass, &block)
25
- end
26
-
27
- # Custom implementation of camelize without ActiveSupport
28
- def custom_camelize(string)
29
- string = string.gsub("/", "::")
30
-
31
- string.gsub(/(?:^|_|::)([a-z])/) do |match|
32
- if match.include?("::")
33
- "::#{match[-1].upcase}"
34
- else
35
- match[-1].upcase
36
- end
37
- end
38
- end
39
-
40
- # Custom implementation of constantize without ActiveSupport
41
- def custom_constantize(string)
42
- names = string.split("::")
43
- constant = Object
44
- regexp = /^[A-Z][a-zA-Z0-9_]*$/
45
-
46
- names.each do |name|
47
- raise NameError, "#{name} is not a valid constant name!" unless name.match?(regexp)
48
-
49
- constant = constant.const_get(name)
50
- end
51
-
52
- constant
53
- rescue NameError => e
54
- raise NameError, "Uninitialized constant #{string}: #{e.message}"
55
- end
9
+ extend Karafka::Core::Helpers::MinitestLocator.new(
10
+ File.expand_path("../test_helper.rb", __dir__)
11
+ )
56
12
 
57
13
  # Provide `described_class` for minitest/spec — walks the desc hierarchy to find a Class/Module
58
14
  module MinitestDescribedClass
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.9
4
+ version: 2.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -78,6 +78,7 @@ files:
78
78
  - lib/karafka/core/contractable/contract.rb
79
79
  - lib/karafka/core/contractable/result.rb
80
80
  - lib/karafka/core/contractable/rule.rb
81
+ - lib/karafka/core/helpers/minitest_locator.rb
81
82
  - lib/karafka/core/helpers/rspec_locator.rb
82
83
  - lib/karafka/core/helpers/time.rb
83
84
  - lib/karafka/core/instrumentation.rb