Skip to content

Commit

Permalink
Replace dep on dry-configurable with a simple Configuration mod
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Jul 1, 2022
1 parent 295038b commit b50f34b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
1 change: 0 additions & 1 deletion dry-container.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Gem::Specification.new do |spec|

# to update dependencies edit project.yml
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
spec.add_runtime_dependency "dry-configurable", "~> 0.13", ">= 0.13.0"

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
Expand Down
1 change: 0 additions & 1 deletion lib/dry/container.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "dry-configurable"
require "dry/container/error"
require "dry/container/namespace"
require "dry/container/registry"
Expand Down
52 changes: 42 additions & 10 deletions lib/dry/container/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,46 @@

module Dry
class Container
# @api public
class Config
DEFAULT_NAMESPACE_SEPARATOR = "."
DEFAULT_RESOLVER = Resolver.new
DEFAULT_REGISTRY = Registry.new

# @api public
attr_accessor :namespace_separator

# @api public
attr_accessor :resolver

# @api public
attr_accessor :registry

# @api private
def initialize(
namespace_separator: DEFAULT_NAMESPACE_SEPARATOR,
resolver: DEFAULT_RESOLVER,
registry: DEFAULT_REGISTRY
)
@namespace_separator = namespace_separator
@resolver = resolver
@registry = registry
end
end

# @api public
module Configuration
# @api public
def config
@config ||= Config.new
end

# @api public
def configure
yield config
end
end

PREFIX_NAMESPACE = lambda do |namespace, key, config|
[namespace, key].join(config.namespace_separator)
end
Expand Down Expand Up @@ -45,13 +85,9 @@ def inherited(subclass)
end

base.class_eval do
extend ::Dry::Configurable
extend Configuration
extend hooks_mod

setting :registry, default: Dry::Container::Registry.new
setting :resolver, default: Dry::Container::Resolver.new
setting :namespace_separator, default: "."

@_container = ::Concurrent::Hash.new
end
end
Expand All @@ -67,13 +103,9 @@ def initialize(*args, &block)
# @private
def self.included(base)
base.class_eval do
extend ::Dry::Configurable
extend Configuration
prepend Initializer

setting :registry, default: Dry::Container::Registry.new
setting :resolver, default: Dry::Container::Resolver.new
setting :namespace_separator, default: "."

def config
self.class.config
end
Expand Down

0 comments on commit b50f34b

Please sign in to comment.