Class: Capybara::Lightpanda::Cookies::Cookie

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/lightpanda/cookies.rb

Overview

Typed wrapper around a CDP cookie hash so callers don’t have to remember the camelCase keys (‘httpOnly`, `sameSite`, …) the CDP returns. Mirrors ferrum’s Cookies::Cookie. ‘attributes` exposes the raw hash for callers that still need it (e.g. YAML serialization in store/load).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Cookie

Returns a new instance of Cookie.



15
16
17
# File 'lib/capybara/lightpanda/cookies.rb', line 15

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/capybara/lightpanda/cookies.rb', line 13

def attributes
  @attributes
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



39
40
41
# File 'lib/capybara/lightpanda/cookies.rb', line 39

def ==(other)
  other.is_a?(self.class) && other.attributes == attributes
end

#domainObject



21
# File 'lib/capybara/lightpanda/cookies.rb', line 21

def domain    = attributes["domain"]

#expiresObject

Time when the cookie expires, or nil for session cookies (CDP reports session cookies with ‘expires: -1`).



34
35
36
37
# File 'lib/capybara/lightpanda/cookies.rb', line 34

def expires
  exp = attributes["expires"]
  Time.at(exp) if exp.is_a?(Numeric) && exp.positive?
end

#hashObject



45
46
47
# File 'lib/capybara/lightpanda/cookies.rb', line 45

def hash
  attributes.hash
end

#httponly?Boolean Also known as: http_only?

Returns:

  • (Boolean)


26
# File 'lib/capybara/lightpanda/cookies.rb', line 26

def httponly? = attributes["httpOnly"]

#nameObject



19
# File 'lib/capybara/lightpanda/cookies.rb', line 19

def name      = attributes["name"]

#pathObject



22
# File 'lib/capybara/lightpanda/cookies.rb', line 22

def path      = attributes["path"]

#samesiteObject Also known as: same_site



23
# File 'lib/capybara/lightpanda/cookies.rb', line 23

def samesite  = attributes["sameSite"]

#secure?Boolean

Returns:

  • (Boolean)


25
# File 'lib/capybara/lightpanda/cookies.rb', line 25

def secure?   = attributes["secure"]

#session?Boolean

Returns:

  • (Boolean)


27
# File 'lib/capybara/lightpanda/cookies.rb', line 27

def session?  = attributes["session"]

#sizeObject



24
# File 'lib/capybara/lightpanda/cookies.rb', line 24

def size      = attributes["size"]

#to_hObject



49
50
51
# File 'lib/capybara/lightpanda/cookies.rb', line 49

def to_h
  attributes
end

#valueObject



20
# File 'lib/capybara/lightpanda/cookies.rb', line 20

def value     = attributes["value"]