Class: Hanami::Config::Actions
- Inherits:
-
Object
- Object
- Hanami::Config::Actions
- Includes:
- Dry::Configurable
- Defined in:
- lib/hanami/config/actions.rb,
lib/hanami/config/actions/cookies.rb,
lib/hanami/config/actions/sessions.rb,
lib/hanami/config/actions/content_security_policy.rb
Overview
Hanami actions config
This exposes all the settings from the standalone ‘Hanami::Action` class, pre-configured with sensible defaults for actions within a full Hanami app. It also provides additional settings for further integration of actions with other full stack app components.
Defined Under Namespace
Classes: ContentSecurityPolicy, Cookies, Sessions
Instance Attribute Summary collapse
-
#content_security_policy ⇒ Hanami::Config::Actions::ContentSecurityPolicy
Returns the Content Security Policy config for actions.
-
#cookies ⇒ Hanami::Config::Actions::Cookies
Sets or returns a hash of cookie options for actions.
-
#csrf_protection ⇒ Boolean
Sets or returns whether CSRF protection should be enabled for action classes.
-
#method_override ⇒ Boolean
Sets or returns whether HTTP method override should be enabled for action classes.
- #name_inference_base ⇒ Object private
-
#sessions ⇒ Config::Sessions
Sets or returns the session store (and its options) for actions.
- #view_name_inference_base ⇒ Object private
- #view_name_inferrer ⇒ Object private
Instance Method Summary collapse
- #finalize!(app_config) ⇒ Object private
-
#initialize(**options) ⇒ Actions
constructor
private
A new instance of Actions.
Constructor Details
#initialize(**options) ⇒ Actions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Actions.
111 112 113 114 115 116 117 118 |
# File 'lib/hanami/config/actions.rb', line 111 def initialize(*, **) super() @base_config = Hanami::Action.config.dup @content_security_policy = ContentSecurityPolicy.new configure_defaults end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
152 153 154 155 156 157 158 159 160 |
# File 'lib/hanami/config/actions.rb', line 152 def method_missing(name, *args, &block) if config.respond_to?(name) config.public_send(name, *args, &block) elsif base_config.respond_to?(name) base_config.public_send(name, *args, &block) else super end end |
Instance Attribute Details
#content_security_policy ⇒ Hanami::Config::Actions::ContentSecurityPolicy
Returns the Content Security Policy config for actions.
The resulting policy is set as a default ‘“Content-Security-Policy”` response header.
75 76 77 |
# File 'lib/hanami/config/actions.rb', line 75 def content_security_policy @content_security_policy end |
#cookies ⇒ Hanami::Config::Actions::Cookies
Sets or returns a hash of cookie options for actions.
The hash is wrapped by Cookies, which also provides an ‘enabled?` method, returning true in the case of any options provided.
31 |
# File 'lib/hanami/config/actions.rb', line 31 setting :cookies, default: {}, constructor: -> { Cookies.new() } |
#csrf_protection ⇒ Boolean
Sets or returns whether CSRF protection should be enabled for action classes.
Defaults to true if #sessions is enabled. You can override this by explicitly setting a true or false value.
When true, this will include ‘Hanami::Action::CSRFProtection` in all action classes.
65 |
# File 'lib/hanami/config/actions.rb', line 65 setting :csrf_protection |
#method_override ⇒ Boolean
Sets or returns whether HTTP method override should be enabled for action classes.
Defaults to true. You can override this by explicitly setting a true or false value.
When true, this will mount ‘Rack::MethodOverride` in the Rack middleware stack of the App.
89 |
# File 'lib/hanami/config/actions.rb', line 89 setting :method_override, default: true |
#name_inference_base ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
94 |
# File 'lib/hanami/config/actions.rb', line 94 setting :name_inference_base, default: "actions" |
#sessions ⇒ Config::Sessions
Sets or returns the session store (and its options) for actions.
The given values are taken as an argument list to be passed to Config::Sessions#initialize.
The configured session store is used when setting up the app or slice router.
51 |
# File 'lib/hanami/config/actions.rb', line 51 setting :sessions, constructor: proc { |storage, *| Sessions.new(storage, *) } |
#view_name_inference_base ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 |
# File 'lib/hanami/config/actions.rb', line 104 setting :view_name_inference_base, default: "views" |
#view_name_inferrer ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 |
# File 'lib/hanami/config/actions.rb', line 99 setting :view_name_inferrer, default: Slice::ViewNameInferrer |
Instance Method Details
#finalize!(app_config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/hanami/config/actions.rb', line 129 def finalize!(app_config) @base_config.root_directory = app_config.root # 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 content_security_policy default_headers["Content-Security-Policy"] = content_security_policy.to_s end end |