class Shamu::Sessions::CookieStore

Track persistent values in a cookie stored on the user's machine. Values kept in the CookieStore are not encrypted but they are protected by HMAC hashing to ensure that they have not been modified.

To support cookies, in your service it must be instantiated as part of a Rack request and you must add {Shamu::Rack::CookieMiddleware} to your app.

## Adding support to a Rails app

“` # application.rb

config.middleware.use Shamu::Rack::CookiesMiddleware “`

## In a standalone Rack app

“` require “shamu/rack”

app = Rack::Builder.new do

use Shamu::Rack::CookiesMiddleware

end

run app “`

Constants

TTL

How long cookies should be kept.

Public Class Methods

new( private_key = Shamu::Security.private_key ) click to toggle source

@param [String] private_key the private key used to verify cookie

values.
Calls superclass method
# File lib/shamu/sessions/cookie_store.rb, line 54
def initialize( private_key = Shamu::Security.private_key )
  @private_key = private_key

  super()
end

Public Instance Methods

delete( key ) click to toggle source

(see SessionStore#delete)

# File lib/shamu/sessions/cookie_store.rb, line 75
def delete( key )
  cookies.delete( key )
end
fetch( key ) { || ... } click to toggle source

(see SessionStore#fetch)

# File lib/shamu/sessions/cookie_store.rb, line 61
def fetch( key, &block )
  if cookies.key?( key )
    verify_hash( cookies.get( key ) )
  elsif block_given?
    yield
  end
end
set( key, value ) click to toggle source

(see SessionStore#set)

# File lib/shamu/sessions/cookie_store.rb, line 70
def set( key, value )
  cookies.set( key, value: hash_value( value ), secure: true, max_age: TTL )
end