lib/hanami/configuration/actions.rb in hanami-2.0.0.alpha7.1 vs lib/hanami/configuration/actions.rb in hanami-2.0.0.alpha8
- old
+ new
@@ -1,33 +1,40 @@
# frozen_string_literal: true
-# require_relative "application_configuration/cookies"
-# require_relative "application_configuration/sessions"
-# require_relative "application_configuration/content_security_policy"
-# require_relative "configuration"
-# require_relative "view_name_inferrer"
+require "dry/configurable"
+require "hanami/action/configuration"
+require_relative "actions/cookies"
+require_relative "actions/sessions"
+require_relative "actions/content_security_policy"
+require_relative "../application/view_name_inferrer"
module Hanami
class Configuration
+ # Hanami actions configuration
+ #
+ # @since 2.0.0
class Actions
include Dry::Configurable
setting :cookies, default: {}, constructor: -> options { Cookies.new(options) }
setting :sessions, constructor: proc { |storage, *options| Sessions.new(storage, *options) }
setting :csrf_protection
setting :name_inference_base, default: "actions"
setting :view_context_identifier, default: "view.context"
- setting :view_name_inferrer, default: ViewNameInferrer
+ setting :view_name_inferrer, default: Application::ViewNameInferrer
setting :view_name_inference_base, default: "views"
attr_accessor :content_security_policy
+ attr_reader :base_configuration
+ private :base_configuration
+
def initialize(*, **options)
super()
- @base_configuration = Configuration.new
+ @base_configuration = Hanami::Action::Configuration.new
@content_security_policy = ContentSecurityPolicy.new do |csp|
if assets_server_url = options[:assets_server_url]
csp[:script_src] += " #{assets_server_url}"
csp[:style_src] += " #{assets_server_url}"
end
@@ -39,12 +46,12 @@
def finalize!
# A nil value for `csrf_protection` means it has not been explicitly configured
# (neither true nor false), so we can default it to whether sessions are enabled
self.csrf_protection = sessions.enabled? if csrf_protection.nil?
- if self.content_security_policy
- self.default_headers["Content-Security-Policy"] = self.content_security_policy.to_str
+ if content_security_policy
+ default_headers["Content-Security-Policy"] = content_security_policy.to_str
end
end
# Returns the list of available settings
#
@@ -55,11 +62,9 @@
def settings
base_configuration.settings + self.class.settings
end
private
-
- attr_reader :base_configuration
# Apply defaults for base configuration settings
def configure_defaults
self.default_request_format = :html
self.default_response_format = :html