Class: Greed::Cookie::ExpirationHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/greed/cookie/expiration_handler.rb

Instance Method Summary collapse

Instance Method Details

#calculate_expiration(current_time, max_age, expires) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/greed/cookie/expiration_handler.rb', line 13

def calculate_expiration(current_time, max_age, expires)
  {
    expires: if max_age
      current_time + max_age.seconds
    else
      expires
    end,
    retrieved_at: current_time,
  }.tap do |tapped|
    tapped_expires = tapped[:expires]
    return tapped unless tapped_expires # keep session cookie
    raise Expired unless (current_time < tapped_expires) # reject expired cookie
  end
end