lib/dry/rails/railtie.rb in dry-rails-0.1.0 vs lib/dry/rails/railtie.rb in dry-rails-0.2.0
- old
+ new
@@ -14,14 +14,16 @@
Railtie.finalize!
end
# Code-reloading-aware finalization process
#
- # This sets up `Container` and `Import` constants, reloads them if this is in reloading mode,
+ # This sets up `Container` and `Deps` constants, reloads them if this is in reloading mode,
# and registers default components like the railtie itself or the inflector
#
# @api public
+ #
+ # rubocop:disable Metrics/AbcSize
def finalize!
stop_features if reloading?
root_path = ::Rails.root
@@ -31,26 +33,31 @@
default_namespace: name.to_s,
inflector: default_inflector,
system_dir: root_path.join("config/system")
)
+ # Enable :env plugin by default because it is a very common requirement
+ container.use :env, inferrer: -> { ::Rails.env }
+
container.register(:railtie, self)
container.register(:inflector, default_inflector)
set_or_reload(:Container, container)
- set_or_reload(:Import, container.injector)
Dry::Rails.evaluate_initializer(container)
+ set_or_reload(container.auto_inject_constant, container.injector)
+
container.features.each do |feature|
container.boot(feature, from: :rails)
end
container.refresh_boot_files if reloading?
container.finalize!(freeze: !::Rails.env.test?)
end
+ # rubocop:enable Metrics/AbcSize
alias_method :reload, :finalize!
# Stops all configured features (bootable components)
#
# This is *crucial* when reloading code in development mode. Every bootable component
@@ -68,18 +75,18 @@
#
# @return [Dry::Rails::Container]
#
# @api public
def container
- app_namespace.const_get(:Container)
+ app_namespace.const_get(:Container, false)
end
# Return true if we're in code-reloading mode
#
# @api private
def reloading?
- app_namespace.const_defined?(:Container)
+ app_namespace.const_defined?(:Container, false)
end
# Return the default system name
#
# In the dry-system world containers are explicitly named using symbols, so that you can
@@ -116,10 +123,10 @@
ActiveSupport::Inflector
end
# @api private
def set_or_reload(const_name, const)
- if app_namespace.const_defined?(const_name)
+ if app_namespace.const_defined?(const_name, false)
app_namespace.__send__(:remove_const, const_name)
end
app_namespace.const_set(const_name, const)
end