Module: Lotus::Action::Session

Defined in:
lib/lotus/action/session.rb

Overview

Session API

This module isn’t included by default.

Since:

  • 0.1.0

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

Since:

  • 0.1.0

'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

Since:

  • 0.3.0

:__errors

Class Method Summary collapse

Instance Method Summary collapse

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

Since:

  • 0.4.4



27
28
29
30
31
# File 'lib/lotus/action/session.rb', line 27

def self.included(action)
  action.class_eval do
    expose :session
  end
end

Instance Method Details

#sessionHash

Gets the session from the request and expose it as an Hash.

Examples:

require 'lotus/controller'
require 'lotus/action/session'

class Show
  include Lotus::Action
  include Lotus::Action::Session

  def call(params)
    # ...

    # get a value
    session[:user_id] # => '23'

    # set a value
    session[:foo] = 'bar'

    # remove a value
    session[:bax] = nil
  end
end

Returns:

  • (Hash)

    the HTTP session from the request

Since:

  • 0.1.0



60
61
62
# File 'lib/lotus/action/session.rb', line 60

def session
  @_env[SESSION_KEY] ||= {}
end