Skip to content

Commit 2d021b2

Browse files
authored
Switched to Zeitwerk as autoloader. (#46)
Signed-off-by: Hermann Mayer <[email protected]>
1 parent c3d090b commit 2d021b2

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### next
22

3-
* TODO: Replace this bullet point with an actual description of a change.
3+
* Switched to Zeitwerk as autoloader (#46)
44

55
### 1.9.0 (3 January 2025)
66

lib/rimless.rb

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'zeitwerk'
34
require 'active_support'
45
require 'active_support/concern'
56
require 'active_support/configurable'
@@ -22,35 +23,33 @@ module Rimless
2223
# Configure the relative gem code base location
2324
root_path = Pathname.new("#{__dir__}/rimless")
2425

25-
# Top level elements
26-
autoload :Configuration, 'rimless/configuration'
27-
autoload :ConfigurationHandling, 'rimless/configuration_handling'
28-
autoload :AvroHelpers, 'rimless/avro_helpers'
29-
autoload :AvroUtils, 'rimless/avro_utils'
30-
autoload :KafkaHelpers, 'rimless/kafka_helpers'
31-
autoload :Dependencies, 'rimless/dependencies'
32-
autoload :BaseConsumer, 'rimless/base_consumer'
33-
autoload :Consumer, 'rimless/consumer'
34-
autoload :ConsumerJob, 'rimless/consumer_job'
35-
36-
# All Karafka-framework related components
37-
module Karafka
38-
autoload :Base64Interchanger, 'rimless/karafka/base64_interchanger'
39-
autoload :PassthroughMapper, 'rimless/karafka/passthrough_mapper'
40-
autoload :AvroDeserializer, 'rimless/karafka/avro_deserializer'
41-
end
26+
# Setup a Zeitwerk autoloader instance and configure it
27+
loader = Zeitwerk::Loader.for_gem
28+
29+
# Do not auto load some parts of the gem
30+
loader.ignore(root_path.join('compatibility*'))
31+
loader.ignore(root_path.join('initializers*'))
32+
loader.ignore(root_path.join('tasks*'))
33+
loader.ignore(root_path.join('railtie.rb'))
34+
loader.ignore(root_path.join('rspec*'))
35+
36+
# Finish the auto loader configuration
37+
loader.setup
4238

4339
# Load standalone code
4440
require 'rimless/version'
4541
require 'rimless/railtie' if defined? Rails
4642

43+
# Load all initializers of the gem
44+
Dir[root_path.join('initializers/**/*.rb')].sort.each { |path| require path }
45+
4746
# Include top-level features
4847
include Rimless::ConfigurationHandling
4948
include Rimless::AvroHelpers
5049
include Rimless::KafkaHelpers
5150
include Rimless::Dependencies
5251
include Rimless::Consumer
5352

54-
# Load all initializers of the gem
55-
Dir[root_path.join('initializers/**/*.rb')].sort.each { |path| require path }
53+
# Make sure to eager load all SDK constants
54+
loader.eager_load
5655
end

rimless.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ Gem::Specification.new do |spec|
4545
spec.add_dependency 'sparsify', '~> 1.1'
4646
spec.add_dependency 'waterdrop', '~> 1.4'
4747
spec.add_dependency 'webmock', '~> 3.18'
48+
spec.add_dependency 'zeitwerk', '~> 2.6'
4849
end

0 commit comments

Comments
 (0)