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 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.
8 9 10 |
# File 'lib/dommy/internal/cookie_jar.rb', line 8 def initialize @cookies = {} end |
Instance Method Details
#set_cookie(value) ⇒ Object
Parse and store a cookie from a Set-Cookie-style string
18 19 20 21 22 23 24 |
# File 'lib/dommy/internal/cookie_jar.rb', line 18 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
13 14 15 |
# File 'lib/dommy/internal/cookie_jar.rb', line 13 def @cookies.map { |k, v| "#{k}=#{v}" }.join("; ") end |