Module: Ferrum::Cookies::Collection

Includes:
Enumerable
Included in:
Ferrum::Cookies, Page::Cookies
Defined in:
lib/ferrum/cookies/collection.rb,
sig/ferrum/cookies/collection.rbs

Overview

Reading cookies by name, shared by Ferrum::Cookies and Page::Cookies, both of which define each.

Instance Method Summary collapse

Instance Method Details

#[](name, domain: nil, path: nil) ⇒ Cookie?

Returns the first cookie with the given name, narrowed down by domain and path when the name is used by more than one cookie.

Examples:

page.cookies["NID"] # =>
# <Ferrum::Cookies::Cookie:0x0000558624b67a88 @attributes={
#  "name"=>"NID", "value"=>"...", "domain"=>".google.com",
#  "path"=>"/", "expires"=>1583211046.575681, "size"=>178,
#  "httpOnly"=>true, "secure"=>false, "session"=>false
# }>
page.cookies["id", domain: "www.example.com", path: "/app"]

Parameters:

  • name (String) —

    The cookie name to fetch.

  • domain (String, nil) (defaults to: nil) —

    The exact domain of the cookie, e.g. ".example.com" for one sent to every subdomain.

  • path (String, nil) (defaults to: nil) —

    The exact path of the cookie.

  • domain: (String, nil) (defaults to: nil)
  • path: (String, nil) (defaults to: nil)

Returns:

  • (Cookie, nil) —

    The matching cookie.



40
41
42
43
44
# File 'lib/ferrum/cookies/collection.rb', line 40

def [](name, domain: nil, path: nil)
  find do |cookie|
    cookie.name == name && (domain.nil? || cookie.domain == domain) && (path.nil? || cookie.path == path)
  end
end