Skip to content

Commit

Permalink
Add zeitwerk loader
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Oct 14, 2022
1 parent 3cb38bd commit 29c82b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions dry-system.gemspec
Expand Up @@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 2.7.0"

# to update dependencies edit project.yml
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
spec.add_runtime_dependency "dry-auto_inject", ">= 0.4.0"
spec.add_runtime_dependency "dry-configurable", "~> 0.16", ">= 0.16.0"
spec.add_runtime_dependency "dry-container", "~> 0.10", ">= 0.10.0"
Expand Down
18 changes: 18 additions & 0 deletions lib/dry/system.rb
@@ -1,10 +1,26 @@
# frozen_string_literal: true

require "zeitwerk"
require "dry/core"
require_relative "system/provider_source_registry"

module Dry
module System
# @api private
def self.loader
@loader ||= Zeitwerk::Loader.new.tap do |loader|
root = File.expand_path("..", __dir__)
loader.tag = "dry-system"
loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-system.rb")
loader.push_dir(root)
loader.ignore(
"#{root}/dry-system.rb",
"#{root}/dry/system/{constants,errors,stubs,version}.rb"
)
loader.inflector.inflect("dsl" => "DSL")
end
end

# Registers the provider sources in the files under the given path
#
# @api public
Expand Down Expand Up @@ -58,5 +74,7 @@ def self.register_component(name, provider:, &block)
def self.provider_sources
@provider_sources ||= ProviderSourceRegistry.new
end

loader.setup
end
end

0 comments on commit 29c82b3

Please sign in to comment.