Class: Rack::Test::CookieJar
- Inherits:
-
Object
- Object
- Rack::Test::CookieJar
- Defined in:
- lib/rack/test/cookie_jar.rb
Overview
:nodoc:
Constant Summary collapse
- DELIMITER =
'; '.freeze
Instance Method Summary collapse
- #<<(new_cookie) ⇒ Object
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #delete(name) ⇒ Object
-
#for(uri) ⇒ Object
:api: private.
- #get_cookie(name) ⇒ Object
-
#initialize(cookies = [], default_host = DEFAULT_HOST) ⇒ CookieJar
constructor
:api: private.
- #merge(raw_cookies, uri = nil) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(cookies = [], default_host = DEFAULT_HOST) ⇒ CookieJar
:api: private
112 113 114 115 116 |
# File 'lib/rack/test/cookie_jar.rb', line 112 def initialize( = [], default_host = DEFAULT_HOST) @default_host = default_host @cookies = @cookies.sort! end |
Instance Method Details
#<<(new_cookie) ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'lib/rack/test/cookie_jar.rb', line 152 def <<() @cookies.reject! do || .replaces?() end @cookies << @cookies.sort! end |
#[](name) ⇒ Object
118 119 120 121 122 |
# File 'lib/rack/test/cookie_jar.rb', line 118 def [](name) = hash_for(nil) # TODO: Should be case insensitive [name.to_s] && [name.to_s].value end |
#[]=(name, value) ⇒ Object
124 125 126 |
# File 'lib/rack/test/cookie_jar.rb', line 124 def []=(name, value) merge("#{name}=#{Rack::Utils.escape(value)}") end |
#delete(name) ⇒ Object
132 133 134 135 136 |
# File 'lib/rack/test/cookie_jar.rb', line 132 def delete(name) @cookies.reject! do || .name == name end end |
#for(uri) ⇒ Object
:api: private
162 163 164 |
# File 'lib/rack/test/cookie_jar.rb', line 162 def for(uri) hash_for(uri).values.map(&:raw).join(DELIMITER) end |
#get_cookie(name) ⇒ Object
128 129 130 |
# File 'lib/rack/test/cookie_jar.rb', line 128 def (name) hash_for(nil).fetch(name, nil) end |
#merge(raw_cookies, uri = nil) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/rack/test/cookie_jar.rb', line 138 def merge(, uri = nil) return unless if .is_a? String = .split("\n") .reject!(&:empty?) end .each do || = Cookie.new(, uri, @default_host) self << if .valid?(uri) end end |
#to_hash ⇒ Object
166 167 168 169 170 171 172 173 174 |
# File 'lib/rack/test/cookie_jar.rb', line 166 def to_hash = {} hash_for(nil).each do |name, | [name] = .value end end |