diff --git a/README.md b/README.md index 1a8da30..39385c1 100644 --- a/README.md +++ b/README.md @@ -151,9 +151,12 @@ end gem auto-configuring, but you can override settings ```ruby -ActiveDryDeps.config.container = 'MyApp::Container' -ActiveDryDeps.config.inflector = ActiveSupport::Inflector -ActiveDryDeps.config.inject_global_constant = 'Deps' +# config/initializers/active_dry_deps.rb +ActiveDryDeps.configure do |config| + config.container = 'MyApp::Container' + config.inflector = ActiveSupport::Inflector + config.inject_global_constant = 'Deps' +end ``` ### Recommended container setup with [dry-system](https://dry-rb.org/gems/dry-system/) for Rails diff --git a/lib/active_dry_deps.rb b/lib/active_dry_deps.rb index ca91cec..43f6cc4 100644 --- a/lib/active_dry_deps.rb +++ b/lib/active_dry_deps.rb @@ -1,11 +1,13 @@ # frozen_string_literal: true -require_relative 'active_dry_deps/version' -require_relative 'active_dry_deps/configuration' -require_relative 'active_dry_deps/railtie' +require 'active_dry_deps/version' +require 'active_dry_deps/configuration' +require 'active_dry_deps/railtie' module ActiveDryDeps + autoload :Deps, 'active_dry_deps/deps' + class Error < StandardError; end class DependencyNameInvalid < Error; end diff --git a/lib/active_dry_deps/railtie.rb b/lib/active_dry_deps/railtie.rb index a7defb0..f0a9a80 100644 --- a/lib/active_dry_deps/railtie.rb +++ b/lib/active_dry_deps/railtie.rb @@ -3,12 +3,10 @@ module ActiveDryDeps class Railtie < ::Rails::Railtie - config.before_initialize do + config.to_prepare do app_namespace = ::Rails.application.class.to_s.split('::').first ActiveDryDeps.config.container ||= "#{app_namespace}::Container" - require_relative 'deps' - Object.const_set(ActiveDryDeps.config.inject_global_constant, ::ActiveDryDeps::Deps) ActiveDryDeps.config.finalize!(freeze_values: true) end