Class: Dommy::Internal::CookieJar

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeCookieJar

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

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 set_cookie(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

Return all cookies as “name=value; name=value” string



13
14
15
# File 'lib/dommy/internal/cookie_jar.rb', line 13

def to_cookie_string
  @cookies.map { |k, v| "#{k}=#{v}" }.join("; ")
end