1
1
# frozen_string_literal: true
2
2
3
+ require 'zeitwerk'
3
4
require 'active_support'
4
5
require 'active_support/concern'
5
6
require 'active_support/configurable'
@@ -22,35 +23,33 @@ module Rimless
22
23
# Configure the relative gem code base location
23
24
root_path = Pathname . new ( "#{ __dir__ } /rimless" )
24
25
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
42
38
43
39
# Load standalone code
44
40
require 'rimless/version'
45
41
require 'rimless/railtie' if defined? Rails
46
42
43
+ # Load all initializers of the gem
44
+ Dir [ root_path . join ( 'initializers/**/*.rb' ) ] . sort . each { |path | require path }
45
+
47
46
# Include top-level features
48
47
include Rimless ::ConfigurationHandling
49
48
include Rimless ::AvroHelpers
50
49
include Rimless ::KafkaHelpers
51
50
include Rimless ::Dependencies
52
51
include Rimless ::Consumer
53
52
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
56
55
end
0 commit comments