Class: Dommy::Internal::CookieJar
- Inherits:
-
Object
- Object
- Dommy::Internal::CookieJar
- Defined in:
- lib/dommy/internal/cookie_jar.rb
Overview
Manages document cookie storage (in-memory, not persisted). Implements the simple document.cookie key=value; key=value interface.
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
Instance Method Summary collapse
-
#initialize ⇒ CookieJar
constructor
A new instance of CookieJar.
-
#set_cookie(value) ⇒ Object
Parse and store a cookie from a Set-Cookie-style string.
-
#to_cookie_string ⇒ Object
Return all cookies as “name=value; name=value” string.
Constructor Details
#initialize ⇒ CookieJar
Returns a new instance of CookieJar.
10 11 12 |
# File 'lib/dommy/internal/cookie_jar.rb', line 10 def initialize @cookies = {} end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
8 9 10 |
# File 'lib/dommy/internal/cookie_jar.rb', line 8 def @cookies end |
Instance Method Details
#set_cookie(value) ⇒ Object
Parse and store a cookie from a Set-Cookie-style string
20 21 22 23 24 25 26 |
# File 'lib/dommy/internal/cookie_jar.rb', line 20 def (value) pair = value.to_s.split(";", 2).first.to_s.strip return if pair.empty? key, val = pair.split("=", 2) @cookies[key.to_s.strip] = val.to_s.strip if key end |
#to_cookie_string ⇒ Object
Return all cookies as “name=value; name=value” string
15 16 17 |
# File 'lib/dommy/internal/cookie_jar.rb', line 15 def @cookies.map { |k, v| "#{k}=#{v}" }.join("; ") end |