Class: Watobo::Cookie

Inherits:
Parameter show all
Defined in:
lib/watobo/core/cookie.rb

Overview

Set-Cookie: mycookie=b41dc9e55d6163f78321996b10c940edcec1b4e55a76464c4e9d25e160ac0ec5b769806b; path=/; secure

Instance Attribute Summary collapse

Attributes inherited from Parameter

#location

Instance Method Summary collapse

Constructor Details

#initialize(prefs) ⇒ Cookie

Returns a new instance of Cookie.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/watobo/core/cookie.rb', line 17

def initialize(prefs)
  @secure = false
  @http_only = false
  
  if prefs.respond_to? :has_key?
    @secure = prefs.has_key?(:secure) ? prefs[:secure] : false
    @http_only = prefs.has_key?(:http_only) ? prefs[:http_only] : false
    @location = :cookie
    @path = prefs[:path]
    @name = prefs[:name]
    @value = prefs[:value]
  else
   # puts "= NEW COOKIE ="
   # puts prefs
   # puts prefs.class
    chunks = prefs.split(";")
    # first chunk
    @name, @value = chunks.first.split(":").last.split("=")
    
    m = prefs.match(/path=([^;]*)/)
    @path = m.nil? ? "" : m[1].strip
    @secure = true if chunks.select{|c| c =~ /Secure/i }
    @http_only = true if chunks.select{|c| c =~ /HttpOnly/i }
  end

  #if prefs.is_a? Hash
  #  #TODO: create cookie with hash-settings
  #  else
  #  raise ArgumentError, "Need hash (:name, :value, ...) or string (Set-Cookie:...)"
  #end
end

Instance Attribute Details

#http_onlyObject (readonly)

Returns the value of attribute http_only.



11
12
13
# File 'lib/watobo/core/cookie.rb', line 11

def http_only
  @http_only
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/watobo/core/cookie.rb', line 7

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/watobo/core/cookie.rb', line 9

def path
  @path
end

#secureObject (readonly)

Returns the value of attribute secure.



10
11
12
# File 'lib/watobo/core/cookie.rb', line 10

def secure
  @secure
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/watobo/core/cookie.rb', line 8

def value
  @value
end

Instance Method Details

#to_sObject



13
14
15
# File 'lib/watobo/core/cookie.rb', line 13

def to_s
  "#{@name}=#{@value}"
end