Class: Cookie::Header

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/cookie/header.rb,
lib/cookie/header/attribute.rb

Overview

Models a transient, new cookie on the server that can be serialized into an HTTP ‘Set-Cookie’ header

Defined Under Namespace

Classes: Attribute

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookie, attributes = Attribute::Set::EMPTY) ⇒ Header

Returns a new instance of Header.



22
23
24
# File 'lib/cookie/header.rb', line 22

def initialize(cookie, attributes = Attribute::Set::EMPTY)
  @cookie, @attributes = cookie, attributes
end

Class Method Details

.build(name, value, attributes) ⇒ Object



18
19
20
# File 'lib/cookie/header.rb', line 18

def self.build(name, value, attributes)
  new(Cookie.new(name, value), attributes)
end

Instance Method Details

#deleteObject



50
51
52
# File 'lib/cookie/header.rb', line 50

def delete
  new(Empty.new(cookie.name), attributes.merge(Attribute::Expired))
end

#http_onlyObject



46
47
48
# File 'lib/cookie/header.rb', line 46

def http_only
  with_attribute(Attribute::HttpOnly.instance)
end

#secureObject



42
43
44
# File 'lib/cookie/header.rb', line 42

def secure
  with_attribute(Attribute::Secure.instance)
end

#to_sObject



54
55
56
# File 'lib/cookie/header.rb', line 54

def to_s
  "#{cookie}#{attributes}"
end

#with_domain(domain) ⇒ Object



26
27
28
# File 'lib/cookie/header.rb', line 26

def with_domain(domain)
  with_attribute(Attribute::Domain.new(domain))
end

#with_expires(time) ⇒ Object



38
39
40
# File 'lib/cookie/header.rb', line 38

def with_expires(time)
  with_attribute(Attribute::Expires.new(time))
end

#with_max_age(seconds) ⇒ Object



34
35
36
# File 'lib/cookie/header.rb', line 34

def with_max_age(seconds)
  with_attribute(Attribute::MaxAge.new(seconds))
end

#with_path(path) ⇒ Object



30
31
32
# File 'lib/cookie/header.rb', line 30

def with_path(path)
  with_attribute(Attribute::Path.new(path))
end