Module: Hanami::Action::Session
- Defined in:
- lib/hanami/action/session.rb
Overview
Session API
This module isn’t included by default.
Constant Summary collapse
- SESSION_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key that returns raw session from the Rack env
'rack.session'.freeze
- ERRORS_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key that is used by flash to transport errors
:__errors
Class Method Summary collapse
-
.included(action) ⇒ Object
private
Add session to default exposures.
Instance Method Summary collapse
-
#errors ⇒ Hanami::Validations::Errors
Read errors from flash or delegate to the superclass.
-
#session ⇒ Hash
Gets the session from the request and expose it as an Hash.
Class Method Details
.included(action) ⇒ 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.
Add session to default exposures
27 28 29 30 31 |
# File 'lib/hanami/action/session.rb', line 27 def self.included(action) action.class_eval do _expose :session, :flash end end |
Instance Method Details
#errors ⇒ Hanami::Validations::Errors
Read errors from flash or delegate to the superclass
72 73 74 |
# File 'lib/hanami/action/session.rb', line 72 def errors flash[ERRORS_KEY] || params.respond_to?(:errors) && params.errors end |
#session ⇒ Hash
Gets the session from the request and expose it as an Hash.
60 61 62 |
# File 'lib/hanami/action/session.rb', line 60 def session @_env[SESSION_KEY] ||= {} end |