Class: Arrow::CookieSet
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/arrow/cookieset.rb
Overview
An object class which provides a convenient way of accessing a set of Arrow::Cookies.
Synopsis
cset = Arrow::CookieSet.new()
cset = Arrow::CookieSet.new( cookies )
cset['cookiename'] # => Arrow::Cookie
cset['cookiename'] = cookie_object
cset['cookiename'] = 'cookievalue'
cset[:cookiename] = 'cookievalue'
cset << Arrow::Cookie.new( *args )
cset.include?( 'cookiename' )
cset.include?( cookie_object )
cset.each do |cookie|
...
end
Authors
-
Michael Granger <[email protected]>
-
Jeremiah Jordan <[email protected]>
Please see the file LICENSE in the top-level directory for licensing details.
Instance Method Summary collapse
-
#<<(cookie) ⇒ Object
Append operator: Add the given
cookie
to the set, replacing an existing cookie with the same name if one exists. -
#[](name) ⇒ Object
Index operator method: returns the Arrow::Cookie with the given
name
if it exists in the cookieset. -
#[]=(name, value) ⇒ Object
Index set operator method: set the cookie that corresponds to the given
name
tovalue
. -
#include?(name_or_cookie) ⇒ Boolean
(also: #key?)
Returns
true
if the CookieSet includes either a cookie with the given name or an Arrow::Cookie object. -
#initialize(*cookies) ⇒ CookieSet
constructor
Create a new CookieSet prepopulated with the given cookies.
-
#length ⇒ Object
(also: #size)
Returns the number of cookies in the cookieset.
Methods inherited from Object
deprecate_class_method, deprecate_method, inherited
Constructor Details
#initialize(*cookies) ⇒ CookieSet
Create a new CookieSet prepopulated with the given cookies
48 49 50 |
# File 'lib/arrow/cookieset.rb', line 48 def initialize( * ) @cookie_set = Set.new( .flatten ) end |
Instance Method Details
#<<(cookie) ⇒ Object
Append operator: Add the given cookie
to the set, replacing an existing cookie with the same name if one exists.
99 100 101 102 103 104 |
# File 'lib/arrow/cookieset.rb', line 99 def <<( ) @cookie_set.delete( ) @cookie_set.add( ) return self end |
#[](name) ⇒ Object
Index operator method: returns the Arrow::Cookie with the given name
if it exists in the cookieset.
69 70 71 72 |
# File 'lib/arrow/cookieset.rb', line 69 def []( name ) name = name.to_s return @cookie_set.find() {|| .name == name } end |
#[]=(name, value) ⇒ Object
Index set operator method: set the cookie that corresponds to the given name
to value
. If value
is not an Arrow::Cookie, one with be created and its value set to value
.
78 79 80 81 82 83 84 |
# File 'lib/arrow/cookieset.rb', line 78 def []=( name, value ) value = Arrow::Cookie.new( name.to_s, value ) unless value.is_a?( Arrow::Cookie ) raise ArgumentError, "cannot set a cookie named '%s' with a key of '%s'" % [ value.name, name ] if value.name.to_s != name.to_s self << value end |
#include?(name_or_cookie) ⇒ Boolean Also known as: key?
Returns true
if the CookieSet includes either a cookie with the given name or an Arrow::Cookie object.
89 90 91 92 93 |
# File 'lib/arrow/cookieset.rb', line 89 def include?( ) return true if @cookie_set.include?( ) name = .to_s return self[name] ? true : false end |
#length ⇒ Object Also known as: size
Returns the number of cookies in the cookieset
61 62 63 |
# File 'lib/arrow/cookieset.rb', line 61 def length return @cookie_set.length end |