lib/hanami/config.rb in hanami-2.1.0 vs lib/hanami/config.rb in hanami-2.2.0.beta1
- old
+ new
@@ -108,11 +108,16 @@
#
# @return [Array<String>] array of relative paths
#
# @api public
# @since 2.0.0
- setting :no_auto_register_paths, default: %w[entities]
+ setting :no_auto_register_paths, default: [
+ "db",
+ "entities",
+ "relations",
+ "structs"
+ ]
# @!attribute [rw] base_url
# Sets the base URL for app's web server.
#
# This is passed to the {Slice::ClassMethods#router router} and used for generating links.
@@ -214,10 +219,24 @@
#
# @api public
# @since 2.0.0
attr_reader :actions
+ # Returns the app's db config, or a null config if hanami-db is not bundled.
+ #
+ # @example When hanami-db is bundled
+ # config.db.import_from_parent # => false
+ #
+ # @example When hanami-db is not bundle
+ # config.db.import_from_parent # => NoMethodError
+ #
+ # @return [Hanami::Config::DB, Hanami::Config::NullConfig]
+ #
+ # @api public
+ # @since 2.2.0
+ attr_reader :db
+
# Returns the app's middleware stack, or nil if hanami-router is not bundled.
#
# Use this to configure middleware that should apply to all routes.
#
# @example
@@ -286,45 +305,53 @@
self.root = Dir.pwd
self.render_errors = (env == :production)
self.render_detailed_errors = (env == :development)
load_from_env
- @logger = Config::Logger.new(env: env, app_name: app_name)
@actions = load_dependent_config("hanami-controller") {
require_relative "config/actions"
Actions.new
}
+ @assets = load_dependent_config("hanami-assets") {
+ require_relative "config/assets"
+ Hanami::Config::Assets.new
+ }
+
+ @db = load_dependent_config("hanami-db") { DB.new }
+
+ @logger = Config::Logger.new(env: env, app_name: app_name)
+
+ @middleware = load_dependent_config("hanami-router") {
+ Slice::Routing::Middleware::Stack.new
+ }
+
@router = load_dependent_config("hanami-router") {
require_relative "config/router"
- @middleware = Slice::Routing::Middleware::Stack.new
Router.new(self)
}
@views = load_dependent_config("hanami-view") {
require_relative "config/views"
Views.new
}
- @assets = load_dependent_config("hanami-assets") {
- require_relative "config/assets"
- Hanami::Config::Assets.new
- }
-
yield self if block_given?
end
# rubocop:enable Metrics/AbcSize
# @api private
def initialize_copy(source)
super
@app_name = app_name.dup
- @assets = source.assets.dup
@actions = source.actions.dup
+ @assets = source.assets.dup
+ @db = source.db.dup
+ @logger = source.logger.dup
@middleware = source.middleware.dup
@router = source.router.dup.tap do |router|
router.instance_variable_set(:@base_config, self)
end
@views = source.views.dup
@@ -479,10 +506,10 @@
else
super
end
end
- def respond_to_missing?(name, _incude_all = false)
+ def respond_to_missing?(name, _include_all = false)
config.respond_to?(name) || super
end
end
end