Class: Unwind::CookieHash
- Inherits:
-
Hash
- Object
- Hash
- Unwind::CookieHash
- Defined in:
- lib/unwind.rb
Overview
borrowed (stolen) from HTTParty with minor updates to handle all cookies existing in a single string
Constant Summary collapse
- CLIENT_COOKIES =
%w{path expires domain path secure httponly}
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.to_cookie_string(*cookie_strings) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/unwind.rb', line 177 def self.(*) h = CookieHash.new .each do |cs| h.(cs) end h. end |
Instance Method Details
#add_cookies(value) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/unwind.rb', line 157 def (value) case value when Hash merge!(value) when String value = value.gsub(/expires=[\w,\s\-\:]+;/i, '') value = value.gsub(/httponly[\,\;]*/i, '') value.split(/[;,]\s/).each do || array = .split('=') self[array[0].strip.to_sym] = array[1] end else raise "add_cookies only takes a Hash or a String" end end |
#to_cookie_string ⇒ Object
173 174 175 |
# File 'lib/unwind.rb', line 173 def delete_if { |k, v| CLIENT_COOKIES.include?(k.to_s.downcase) }.collect { |k, v| "#{k}=#{v}" }.join("; ") end |