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
164 165 166 167 168 169 170 171 |
# File 'lib/unwind.rb', line 164 def self.(*) h = CookieHash.new .each do |cs| h.(cs) end h. end |
Instance Method Details
#add_cookies(value) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/unwind.rb', line 144 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
160 161 162 |
# File 'lib/unwind.rb', line 160 def delete_if { |k, v| CLIENT_COOKIES.include?(k.to_s.downcase) }.collect { |k, v| "#{k}=#{v}" }.join("; ") end |