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.



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

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

Instance Method Details

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



41
42
43
# File 'lib/capybara/lightpanda/cookies.rb', line 41

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

#domainObject



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

def domain    = attributes["domain"]

#expiresObject

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



36
37
38
39
# File 'lib/capybara/lightpanda/cookies.rb', line 36

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

#hashObject



47
48
49
# File 'lib/capybara/lightpanda/cookies.rb', line 47

def hash
  attributes.hash
end

#httponly?Boolean Also known as: http_only?

Returns:

  • (Boolean)


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

def httponly? = attributes["httpOnly"]

#nameObject



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

def name      = attributes["name"]

#pathObject



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

def path      = attributes["path"]

#samesiteObject Also known as: same_site



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

def samesite  = attributes["sameSite"]

#secure?Boolean

Returns:

  • (Boolean)


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

def secure?   = attributes["secure"]

#session?Boolean

Returns:

  • (Boolean)


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

def session?  = attributes["session"]

#sizeObject



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

def size      = attributes["size"]

#to_hObject



51
52
53
# File 'lib/capybara/lightpanda/cookies.rb', line 51

def to_h
  attributes
end

#valueObject



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

def value     = attributes["value"]