Module: WebPipe::Session

Included in:
Conn
Defined in:
lib/web_pipe/extensions/session/session.rb

Overview

See the docs for the extension linked from the README.

Constant Summary collapse

SESSION_KEY =

Type for session keys.

Types::Strict::String

Instance Method Summary collapse

Instance Method Details

#add_session(key, value) ⇒ Conn

Adds given key/value pair to the session.

Parameters:

  • key (SESSION_KEY[])

    Session key

  • value (Any)

    Value

Returns:



42
43
44
45
# File 'lib/web_pipe/extensions/session/session.rb', line 42

def add_session(key, value)
  session[SESSION_KEY[key]] = value
  self
end

#clear_sessionConn

Deletes everything from the session.

Returns:



59
60
61
62
# File 'lib/web_pipe/extensions/session/session.rb', line 59

def clear_session
  session.clear
  self
end

#delete_session(key) ⇒ Conn

Deletes given key form the session.

Parameters:

Returns:



51
52
53
54
# File 'lib/web_pipe/extensions/session/session.rb', line 51

def delete_session(key)
  session.delete(SESSION_KEY[key])
  self
end

#fetch_session(*args, &block) ⇒ Any

Fetches given key from the session.

Parameters:

  • key (SESSION_KEY[])

    Session key to fetch

  • default (Any)

    Default value if key is not found

Yield Returns:

  • Default value if key is not found and default is not given

Returns:

  • (Any)

Raises:

  • KeyError When key is not found and not default nor block are given



32
33
34
35
# File 'lib/web_pipe/extensions/session/session.rb', line 32

def fetch_session(*args, &block)
  SESSION_KEY[args[0]]
  session.fetch(*args, &block)
end

#sessionRack::Session::Abstract::SessionHash

Returns Rack::Session's hash

Returns:

  • (Rack::Session::Abstract::SessionHash)


17
18
19
20
21
22
23
# File 'lib/web_pipe/extensions/session/session.rb', line 17

def session
  env.fetch(Rack::RACK_SESSION) do
    raise ConnSupport::MissingMiddlewareError.new(
      'session', 'Rack::Session', 'https://www.rubydoc.info/github/rack/rack/Rack/Session'
    )
  end
end