lib/dry/component/container.rb in dry-component-0.2.0 vs lib/dry/component/container.rb in dry-component-0.3.0

- old
+ new

@@ -1,44 +1,36 @@ require 'pathname' require 'inflecto' +require 'dry-configurable' require 'dry-container' require 'dry/component/injector' require 'dry/component/loader' -require 'dry/component/config' module Dry module Component class Container + extend Dry::Configurable extend Dry::Container::Mixin - setting :env setting :name setting :root, Pathname.pwd.freeze setting :core_dir, 'component'.freeze setting :auto_register - setting :options setting :loader, Dry::Component::Loader def self.inherited(subclass) super subclass.const_set :Inject, subclass.injector end - def self.configure(env = config.env, &block) - return self if configured? + def self.configure(&block) + super(&block) - super() do |config| - yield(config) if block - config.options = Config.load(root, config.name, env) - end - load_paths!(config.core_dir) - @configured = true - self end def self.import(other) case other @@ -49,22 +41,14 @@ imports.update(other.config.name => other) end end end - def self.options - config.options - end - def self.finalize(name, &block) finalizers[name] = proc { block.(self) } end - def self.configured? - @configured - end - def self.finalize!(&_block) yield(self) if block_given? imports.each do |ns, container| import_container(ns, container.finalize!) @@ -169,12 +153,16 @@ end def self.load_paths!(*dirs) dirs.map(&:to_s).each do |dir| path = root.join(dir) + + next if load_paths.include?(path) + load_paths << path $LOAD_PATH.unshift(path.to_s) end + self end def self.load_paths @load_paths ||= []