Class: Watobo::Cookie
Overview
Set-Cookie: mycookie=b41dc9e55d6163f78321996b10c940edcec1b4e55a76464c4e9d25e160ac0ec5b769806b; path=/; secure
Instance Attribute Summary collapse
-
#http_only ⇒ Object
readonly
Returns the value of attribute http_only.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#secure ⇒ Object
readonly
Returns the value of attribute secure.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Parameter
Instance Method Summary collapse
-
#initialize(prefs) ⇒ Cookie
constructor
A new instance of Cookie.
- #to_s ⇒ Object
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_only ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/watobo/core/cookie.rb', line 7 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/watobo/core/cookie.rb', line 9 def path @path end |
#secure ⇒ Object (readonly)
Returns the value of attribute secure.
10 11 12 |
# File 'lib/watobo/core/cookie.rb', line 10 def secure @secure end |
#value ⇒ Object (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_s ⇒ Object
13 14 15 |
# File 'lib/watobo/core/cookie.rb', line 13 def to_s "#{@name}=#{@value}" end |