Class: Watir::Cookies
- Includes:
- Enumerable
- Defined in:
- lib/watir-classic/cookies.rb
Instance Method Summary collapse
- #add(name, value, options = {}) ⇒ Object
- #clear ⇒ Object
- #delete(name) ⇒ Object
- #each ⇒ Object
-
#initialize(page_container) ⇒ Cookies
constructor
A new instance of Cookies.
Constructor Details
#initialize(page_container) ⇒ Cookies
Returns a new instance of Cookies.
7 8 9 |
# File 'lib/watir-classic/cookies.rb', line 7 def initialize(page_container) @page_container = page_container end |
Instance Method Details
#add(name, value, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/watir-classic/cookies.rb', line 18 def add name, value, ={} = .map do |option| k, v = option if k == :expires "#{k}=#{v.gmtime.strftime("%a, %d %b %Y %H:%M:%S UTC")}" elsif k == :secure "secure" if v else "#{k}=#{v}" end end.compact.join("; ") = "; #{options}" unless .empty? @page_container.document. = "#{name}=#{value}#{options}" end |
#clear ⇒ Object
70 71 72 |
# File 'lib/watir-classic/cookies.rb', line 70 def clear each {|| delete [:name]} end |
#delete(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/watir-classic/cookies.rb', line 34 def delete name = {:expires => ::Time.now - 60 * 60 * 24} name, # make sure that the cookie gets deleted # there's got to be some easier way to do this uri = URI.parse(@page_container.url) domain = uri.host paths = uri.path.split("/").reduce([]) do |paths, path| paths << "#{paths.last}/#{path}".squeeze("/") end << "/" subdomains = domain.split(".").reverse.reduce([]) do |subdomains, part| subdomain = "#{part}#{subdomains.last}" subdomain = "." + subdomain unless subdomain == domain subdomains << subdomain end subdomains.each do |subdomain| = .merge :domain => subdomain name, name, .merge(:secure => true) paths.each do |path| = .merge :path => path name, name, .merge(:secure => true) = .merge :path => path name, name, .merge(:secure => true) end end end |
#each ⇒ Object
11 12 13 14 15 16 |
# File 'lib/watir-classic/cookies.rb', line 11 def each @page_container.document..split(";").each do || name, value = .strip.split("=") yield({:name => name, :value => value}) end end |