lib/hanami/configuration.rb in hanami-2.0.0.beta1.1 vs lib/hanami/configuration.rb in hanami-2.0.0.beta2
- old
+ new
@@ -9,11 +9,11 @@
require_relative "constants"
require_relative "configuration/logger"
require_relative "configuration/router"
require_relative "configuration/sessions"
-require_relative "settings/dotenv_store"
+require_relative "settings/env_store"
require_relative "slice/routing/middleware/stack"
module Hanami
# Hanami app configuration
#
@@ -25,23 +25,23 @@
setting :no_auto_register_paths, default: %w[entities]
setting :inflector, default: Dry::Inflector.new
- setting :settings_store, default: Hanami::Settings::DotenvStore
+ setting :settings_store, default: Hanami::Settings::EnvStore.new
- setting :slices do
- setting :shared_component_keys, default: %w[
- inflector
- logger
- notifications
- rack.monitor
- routes
- settings
- ]
- end
+ setting :shared_app_component_keys, default: %w[
+ inflector
+ logger
+ notifications
+ rack.monitor
+ routes
+ settings
+ ]
+ setting :slices
+
setting :base_url, default: "http://0.0.0.0:2300", constructor: ->(url) { URI(url) }
setting :sessions, default: :null, constructor: ->(*args) { Sessions.new(*args) }
setting :logger, cloneable: true
@@ -98,14 +98,13 @@
@app_name = app_name
@environments = DEFAULT_ENVIRONMENTS.clone
@env = env
- # Some default setting values must be assigned at initialize-time to ensure they
- # have appropriate values for the current app
+ # Apply default values that are only knowable at initialize-time (vs require-time)
self.root = Dir.pwd
- self.settings_store = Hanami::Settings::DotenvStore.new.with_dotenv_loaded
+ load_from_env
config.logger = Configuration::Logger.new(env: env, app_name: app_name)
@assets = load_dependent_config("hanami/assets/app_configuration") {
Hanami::Assets::AppConfiguration.new
@@ -197,37 +196,38 @@
@logger_instance || logger.instance
end
private
- # @api private
+ def load_from_env
+ self.slices = ENV["HANAMI_SLICES"]&.split(",")&.map(&:strip)
+ end
+
def apply_env_config(env = self.env)
environments[env].each do |block|
instance_eval(&block)
end
end
# @api private
- def load_dependent_config(require_path, &block)
+ def load_dependent_config(require_path)
require require_path
yield
rescue LoadError => e
raise e unless e.path == require_path
require_relative "configuration/null_configuration"
NullConfiguration.new
end
- # @api private
def method_missing(name, *args, &block)
if config.respond_to?(name)
config.public_send(name, *args, &block)
else
super
end
end
- # @api private
def respond_to_missing?(name, _incude_all = false)
config.respond_to?(name) || super
end
end
end