Class: Capybara::Mechanize::Driver
- Inherits:
-
Object
- Object
- Capybara::Mechanize::Driver
- Defined in:
- lib/extensions/capybara-mechanize-extensions.rb
Overview
Cookie handling extensions
Instance Method Summary collapse
- #add_cookie(attribs) ⇒ Object
- #cookie_named(name) ⇒ Object
- #cookies ⇒ Object
- #delete_all_cookies ⇒ Object
- #delete_cookie(cookie_name) ⇒ Object
- #delete_cookies_in_domain(domain) ⇒ Object
Instance Method Details
#add_cookie(attribs) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/extensions/capybara-mechanize-extensions.rb', line 54 def (attribs) = HTTP::Cookie.new( attribs[:name], attribs[:value], :domain => attribs[:domain], :for_domain => true, :path => '/', :expires => attribs[:expires], :secure => attribs[:secure], :httponly => attribs[:httponly] ) browser.agent..add() end |
#cookie_named(name) ⇒ Object
28 29 30 |
# File 'lib/extensions/capybara-mechanize-extensions.rb', line 28 def (name) .find { |c| c[:name] == name } end |
#cookies ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/extensions/capybara-mechanize-extensions.rb', line 6 def = [] browser.agent..jar.each do |domain| domain[1].each do |path| path[1].each do || .push({ :name => [1].name, :value => [1].value, :domain => [1].domain, :secure => [1].secure, :expires => [1].expires, :httponly => [1].httponly, :path => [1].path }) end end end end |
#delete_all_cookies ⇒ Object
44 45 46 |
# File 'lib/extensions/capybara-mechanize-extensions.rb', line 44 def browser.agent..clear! end |
#delete_cookie(cookie_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/extensions/capybara-mechanize-extensions.rb', line 32 def () browser.agent..jar.each do |domain| domain[1].each do |path| path[1].each do || if [0] == browser.agent..jar[domain[0]][path[0]].delete([0]) end end end end end |
#delete_cookies_in_domain(domain) ⇒ Object
48 49 50 51 52 |
# File 'lib/extensions/capybara-mechanize-extensions.rb', line 48 def (domain) .each do || ([:name]) if [:domain].include?(domain) end end |