Class: Raw::Cookie
- Inherits:
-
Object
- Object
- Raw::Cookie
- Defined in:
- lib/raw/cgi/cookie.rb
Overview
Encapsulates a HTTP Cookie.
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#max_age ⇒ Object
Returns the value of attribute max_age.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#secure ⇒ Object
Returns the value of attribute secure.
-
#value ⇒ Object
Returns the value of attribute value.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#expires ⇒ Object
When the cookie expires.
-
#expires=(t) ⇒ Object
Set the cookie expiration.
-
#initialize(name = nil, value = nil, expires = nil) ⇒ Cookie
constructor
A new instance of Cookie.
- #to_s ⇒ Object
Constructor Details
#initialize(name = nil, value = nil, expires = nil) ⇒ Cookie
Returns a new instance of Cookie.
11 12 13 14 15 16 17 18 19 |
# File 'lib/raw/cgi/cookie.rb', line 11 def initialize(name = nil, value = nil, expires = nil) @name = name @value = value self.expires = expires @version = 0 # Netscape Cookie THINK: maybe should make this 1 ?? @path = "/" # gmosx: KEEP this! @domain = @secure = @comment = @max_age = nil @discard = @port = nil end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
9 10 11 |
# File 'lib/raw/cgi/cookie.rb', line 9 def comment @comment end |
#domain ⇒ Object
Returns the value of attribute domain.
8 9 10 |
# File 'lib/raw/cgi/cookie.rb', line 8 def domain @domain end |
#max_age ⇒ Object
Returns the value of attribute max_age.
9 10 11 |
# File 'lib/raw/cgi/cookie.rb', line 9 def max_age @max_age end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/raw/cgi/cookie.rb', line 6 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/raw/cgi/cookie.rb', line 8 def path @path end |
#secure ⇒ Object
Returns the value of attribute secure.
8 9 10 |
# File 'lib/raw/cgi/cookie.rb', line 8 def secure @secure end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/raw/cgi/cookie.rb', line 7 def value @value end |
#version ⇒ Object
Returns the value of attribute version.
7 8 9 |
# File 'lib/raw/cgi/cookie.rb', line 7 def version @version end |
Instance Method Details
#expires ⇒ Object
When the cookie expires.
29 30 31 |
# File 'lib/raw/cgi/cookie.rb', line 29 def expires @expires && Time.parse(@expires) end |
#expires=(t) ⇒ Object
Set the cookie expiration.
23 24 25 |
# File 'lib/raw/cgi/cookie.rb', line 23 def expires=(t) @expires = t && (t.is_a?(Time) ? t.httpdate : t.to_s) end |
#to_s ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/raw/cgi/cookie.rb', line 33 def to_s str = "#{@name}=#{@value}" str << "; Version=#{@version}" if @version > 0 str << "; Domain=#{@domain}" if @domain str << "; Expires=#{@expires}" if @expires str << "; Max-Age=#{@max_age}" if @max_age str << "; Comment=#{@comment}" if @comment str << "; Path=#{@path}" if @path str << "; Secure" if @secure return str end |