Class: Rack::Client::CookieJar::Cookie
- Inherits:
-
Struct
- Object
- Struct
- Rack::Client::CookieJar::Cookie
- Defined in:
- lib/rack/client/middleware/cookie_jar/cookie.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#key ⇒ Object
Returns the value of attribute key.
-
#path ⇒ Object
Returns the value of attribute path.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #fuzzy_domain_equal(other_domain) ⇒ Object
- #fuzzy_path_equal(other_path) ⇒ Object
-
#initialize(parts = {}) ⇒ Cookie
constructor
A new instance of Cookie.
- #match?(domain, path) ⇒ Boolean
- #to_header ⇒ Object
- #to_key ⇒ Object
Constructor Details
#initialize(parts = {}) ⇒ Cookie
Returns a new instance of Cookie.
22 23 24 25 26 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 22 def initialize(parts = {}) parts.each do |k,v| send(:"#{k}=", v) end end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain
4 5 6 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 4 def domain @domain end |
#key ⇒ Object
Returns the value of attribute key
4 5 6 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 4 def key @key end |
#path ⇒ Object
Returns the value of attribute path
4 5 6 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 4 def path @path end |
#value ⇒ Object
Returns the value of attribute value
4 5 6 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 4 def value @value end |
Class Method Details
.from(header) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 14 def self.from(header) data = header.split('; ') tuple = data.shift.split('=') parts = data.map {|s| s.split('=') } new parts.inject('key'=> tuple.first, 'value'=> tuple.last) {|h,(k,v)| h.update(k => v)} end |
.merge(bottom, top) ⇒ Object
6 7 8 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 6 def self.merge(bottom, top) bottom.reject {|a| top.any? {|b| a == b } } | top end |
.parse(raw) ⇒ Object
10 11 12 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 10 def self.parse(raw) raw.split(', ').map {|header| from(header) } end |
Instance Method Details
#eql?(other) ⇒ Boolean
37 38 39 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 37 def eql?(other) to_key == other.to_key end |
#fuzzy_domain_equal(other_domain) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 45 def fuzzy_domain_equal(other_domain) if domain =~ /^\./ other_domain =~ /#{Regexp.escape(domain)}$/ else domain == other_domain end end |
#fuzzy_path_equal(other_path) ⇒ Object
53 54 55 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 53 def fuzzy_path_equal(other_path) path == '/' || path == other_path end |
#match?(domain, path) ⇒ Boolean
41 42 43 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 41 def match?(domain, path) fuzzy_domain_equal(domain) && fuzzy_path_equal(path) end |
#to_header ⇒ Object
32 33 34 35 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 32 def to_header hash = members.zip(values).inject({}) {|h,(k,v)| h.update(k => v) }.reject {|k,v| v.nil?} "#{hash.delete('key')}=#{hash.delete('value')}" << ('; ' + hash.map {|(k,v)| "#{k}=#{v}" } * '; ' unless hash.empty?) end |
#to_key ⇒ Object
28 29 30 |
# File 'lib/rack/client/middleware/cookie_jar/cookie.rb', line 28 def to_key [ key, domain, path ] * ';' end |