Skip to content

Commit

Permalink
Switched to Zeitwerk as autoloader. (#27)
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann Mayer <hermann.mayer92@gmail.com>
  • Loading branch information
Jack12816 authored Jan 12, 2025
1 parent 821709b commit e38c79a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### next

* TODO: Replace this bullet point with an actual description of a change.
* Switched to Zeitwerk as autoloader (#27)

### 1.5.1 (9 January 2025)

Expand Down
1 change: 1 addition & 0 deletions factory_bot_instrumentation.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ Gem::Specification.new do |spec|
spec.add_dependency 'factory_bot', '~> 6.2'
spec.add_dependency 'rails', '>= 6.1'
spec.add_dependency 'retries', '>= 0.0.5'
spec.add_dependency 'zeitwerk', '~> 2.6'
end
51 changes: 51 additions & 0 deletions lib/factory_bot/instrumentation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

require 'active_support'
require 'active_support/concern'
require 'active_support/configurable'
require 'active_support/cache'
require 'active_support/core_ext/hash'
require 'active_support/time'
require 'active_support/time_with_zone'
require 'retries'
require 'factory_bot'

module FactoryBot
# The top level namespace for the factory_bot_instrumentation gem.
module Instrumentation
# Setup a Zeitwerk autoloader instance and configure it
loader = Zeitwerk::Loader.for_gem_extension(FactoryBot)

# Finish the auto loader configuration
loader.setup

# Make sure to eager load all constants
loader.eager_load

class << self
attr_writer :configuration

# Retrieve the current configuration object.
#
# @return [Configuration]
def configuration
@configuration ||= Configuration.new
end

# Configure the concern by providing a block which takes
# care of this task. Example:
#
# FactoryBot::Instrumentation.configure do |conf|
# # conf.xyz = [..]
# end
def configure
yield(configuration)
end

# Reset the current configuration with the default one.
def reset_configuration!
self.configuration = Configuration.new
end
end
end
end
44 changes: 1 addition & 43 deletions lib/factory_bot_instrumentation.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,3 @@
# frozen_string_literal: true

require 'active_support'
require 'active_support/concern'
require 'active_support/configurable'
require 'active_support/cache'
require 'active_support/core_ext/hash'
require 'active_support/time'
require 'active_support/time_with_zone'
require 'retries'

require 'factory_bot'
require 'factory_bot/instrumentation/configuration'
require 'factory_bot/instrumentation/engine'

module FactoryBot
# The top level namespace for the factory_bot_instrumentation gem.
module Instrumentation
class << self
attr_writer :configuration
end

# Retrieve the current configuration object.
#
# @return [Configuration]
def self.configuration
@configuration ||= Configuration.new
end

# Configure the concern by providing a block which takes
# care of this task. Example:
#
# FactoryBot::Instrumentation.configure do |conf|
# # conf.xyz = [..]
# end
def self.configure
yield(configuration)
end

# Reset the current configuration with the default one.
def self.reset_configuration!
self.configuration = Configuration.new
end
end
end
require 'factory_bot/instrumentation'

0 comments on commit e38c79a

Please sign in to comment.