Class: Hanami::Config::Actions::Sessions

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/config/actions/sessions.rb

Overview

Config for HTTP session middleware in Hanami actions.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage = nil, *options) ⇒ Sessions

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 ‘Sessions`.

You should not need to initialize this class directly. Instead use Hanami::Config::Actions#sessions=.

Examples:

config.actions.sessions = :cookie, {secret: "xyz"}

Since:

  • 2.0.0



40
41
42
43
# File 'lib/hanami/config/actions/sessions.rb', line 40

def initialize(storage = nil, *options)
  @storage = storage
  @options = options
end

Instance Attribute Details

#optionsArray (readonly)

Returns the configured session storage options

Returns:

  • (Array)

Since:

  • 2.0.0



28
29
30
# File 'lib/hanami/config/actions/sessions.rb', line 28

def options
  @options
end

#storageSymbol (readonly)

Returns the configured session storage

Returns:

  • (Symbol)

Since:

  • 2.0.0



20
21
22
# File 'lib/hanami/config/actions/sessions.rb', line 20

def storage
  @storage
end

Instance Method Details

#enabled?Boolean

Returns true if sessions have been enabled.

Returns:

  • (Boolean)

Since:

  • 2.0.0



51
52
53
# File 'lib/hanami/config/actions/sessions.rb', line 51

def enabled?
  !storage.nil?
end

#middlewareArray<(Symbol, Array)>

Returns an array of the session storage middleware name and its options, or an empty array if sessions have not been enabled.

Returns:

  • (Array<(Symbol, Array)>)

Since:

  • 2.0.0



62
63
64
65
66
# File 'lib/hanami/config/actions/sessions.rb', line 62

def middleware
  return [] unless enabled?

  [storage_middleware, options].flatten(1)
end