Class: HTTP::Security::Headers::SetCookie::Cookie

Inherits:
Object
  • Object
show all
Defined in:
lib/http/security/headers/set_cookie.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directives = {}) ⇒ Cookie

Returns a new instance of Cookie.



21
22
23
24
25
26
27
28
# File 'lib/http/security/headers/set_cookie.rb', line 21

def initialize(directives={})
  @cookie    = directives[:cookie]
  @path      = directives[:path]
  @domain    = directives[:domain]
  @expires   = directives[:expires]
  @secure    = directives[:secure]
  @http_only = directives[:http_only]
end

Instance Attribute Details

Returns the value of attribute cookie.



13
14
15
# File 'lib/http/security/headers/set_cookie.rb', line 13

def cookie
  @cookie
end

#domainObject (readonly)

Returns the value of attribute domain.



17
18
19
# File 'lib/http/security/headers/set_cookie.rb', line 17

def domain
  @domain
end

#expiresObject (readonly)

Returns the value of attribute expires.



19
20
21
# File 'lib/http/security/headers/set_cookie.rb', line 19

def expires
  @expires
end

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/http/security/headers/set_cookie.rb', line 15

def path
  @path
end

Instance Method Details

#http_only?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/http/security/headers/set_cookie.rb', line 42

def http_only?
  !!@http_only
end

#nameObject



30
31
32
# File 'lib/http/security/headers/set_cookie.rb', line 30

def name
  @cookie.keys.first
end

#secure?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/http/security/headers/set_cookie.rb', line 38

def secure?
  !!@secure
end

#to_sObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/http/security/headers/set_cookie.rb', line 46

def to_s
  str = "#{name}=#{value}"

  str << "; Path=#{@path}"                if @path
  str << "; Domain=#{@domain}"            if @domain
  str << "; Expires=#{@expires.httpdate}" if @expires
  str << "; Secure"                       if @secure
  str << "; HttpOnly"                     if @http_only

  return str
end

#valueObject



34
35
36
# File 'lib/http/security/headers/set_cookie.rb', line 34

def value
  @cookie.values.first
end