The container for cookies. Features methods for storing and retrieving cookies easily.
Included modules
Public class methods
new
(jar_size)
[show source]
# File lib/rufus/verbs/cookies.rb, line 257 257: def initialize (jar_size) 258: 259: @per_domain = LruHash.new jar_size 260: end
Public instance methods
add_cookie
(domain, path, cookie)
[show source]
# File lib/rufus/verbs/cookies.rb, line 270 270: def add_cookie (domain, path, cookie) 271: 272: (@per_domain[domain] ||= {})[CookieKey.new(path, cookie)] = cookie 273: end
fetch_cookies
(host, path)
Retrieves the cookies that matches the combination host/path. If the retrieved cookie is expired, will remove it from the jar and return nil.
[show source]
# File lib/rufus/verbs/cookies.rb, line 287 287: def fetch_cookies (host, path) 288: 289: c = do_fetch(@per_domain[host], path) 290: 291: h, d = split_host host 292: c += do_fetch(@per_domain[d], path) if d 293: 294: c 295: end
remove_cookie
(domain, path, cookie)
[show source]
# File lib/rufus/verbs/cookies.rb, line 275 275: def remove_cookie (domain, path, cookie) 276: 277: (d = @per_domain[domain]) 278: return unless d 279: d.delete CookieKey.new(path, cookie) 280: end
size
()
Returns the count of cookies currently stored in this jar.
[show source]
# File lib/rufus/verbs/cookies.rb, line 265 265: def size 266: 267: @per_domain.keys.inject(0) { |i, d| i + @per_domain[d].size } 268: end