Class: WebUnit::Cookies
- Includes:
- Singleton
- Defined in:
- lib/webunit/cookie.rb
Instance Attribute Summary collapse
-
#cookies ⇒ Object
Returns the value of attribute cookies.
Class Method Summary collapse
-
.add(n, v, p = '/') ⇒ Object
— Cookies.add( name, value, path ).
-
.clear ⇒ Object
— Cookies.clear.
-
.has?(name) ⇒ Boolean
— Cookies.has?.
- .header(target) ⇒ Object
-
.list ⇒ Object
— Cookies.list.
- .update(set_cookie_response) ⇒ Object
Instance Method Summary collapse
- #add(n, v, p) ⇒ Object
- #clear ⇒ Object
- #has?(name) ⇒ Boolean
- #header(target) ⇒ Object
-
#initialize ⇒ Cookies
constructor
A new instance of Cookies.
- #list ⇒ Object
- #update(set_cookie_response) ⇒ Object
Constructor Details
#initialize ⇒ Cookies
Returns a new instance of Cookies.
15 16 17 |
# File 'lib/webunit/cookie.rb', line 15 def initialize @cookies = {} end |
Instance Attribute Details
#cookies ⇒ Object
Returns the value of attribute cookies.
97 98 99 |
# File 'lib/webunit/cookie.rb', line 97 def @cookies end |
Class Method Details
.add(n, v, p = '/') ⇒ Object
— Cookies.add( name, value, path )
35 36 37 |
# File 'lib/webunit/cookie.rb', line 35 def self::add( n, v, p='/' ) self::instance.add( n, v, p ) end |
.clear ⇒ Object
— Cookies.clear
23 24 25 |
# File 'lib/webunit/cookie.rb', line 23 def self::clear self::instance.clear end |
.has?(name) ⇒ Boolean
— Cookies.has?
62 63 64 |
# File 'lib/webunit/cookie.rb', line 62 def self::has?( name ) self::instance.has?( name ) end |
.header(target) ⇒ Object
83 84 85 |
# File 'lib/webunit/cookie.rb', line 83 def self::header( target ) self::instance.header( target ) end |
.list ⇒ Object
— Cookies.list
50 51 52 |
# File 'lib/webunit/cookie.rb', line 50 def self::list self::instance.list end |
.update(set_cookie_response) ⇒ Object
70 71 72 |
# File 'lib/webunit/cookie.rb', line 70 def self::update( ) self::instance.update( ) end |
Instance Method Details
#add(n, v, p) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/webunit/cookie.rb', line 39 def add( n, v, p ) h = {} h["name"] = n h["value"] = v @cookies[[n,p]] = h end |
#clear ⇒ Object
27 28 29 |
# File 'lib/webunit/cookie.rb', line 27 def clear @cookies = {} end |
#has?(name) ⇒ Boolean
66 67 68 |
# File 'lib/webunit/cookie.rb', line 66 def has?( name ) @cookies.keys.collect{|x|x[0]}.include?( name ) end |
#header(target) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/webunit/cookie.rb', line 87 def header( target ) a = [] @cookies.keys.each do |name,path| if path == nil || ( 'path=' + target ).index( path ) != nil then a.push( name + '=' + @cookies[[name,path]]["value"] ) end end a.size == 0 ? {} : { "Cookie"=>( a.join( '; ' ) ) } end |
#list ⇒ Object
54 55 56 |
# File 'lib/webunit/cookie.rb', line 54 def list @cookies.keys.collect{|x|x[0]} end |
#update(set_cookie_response) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/webunit/cookie.rb', line 74 def update( ) if != nil then .split(',').each do |e| c = ( e.strip ) @cookies[ [ c["name"], c["path"] ] ] = c end end end |