Sha256: 34b210510c1dc89b884b279515e8ebfbb17d21ab2db687f11f8f3b22d138ffa1
Contents?: true
Size: 849 Bytes
Versions: 7
Compression:
Stored size: 849 Bytes
Contents
module Grape class Cookies def initialize @cookies = {} @send_cookies = {} end def read(request) request.cookies.each do |name, value| @cookies[name.to_s] = value end end def write(header) @cookies.select { |key, _value| @send_cookies[key] == true }.each do |name, value| cookie_value = value.is_a?(Hash) ? value : { value: value } Rack::Utils.set_cookie_header! header, name, cookie_value end end def [](name) @cookies[name.to_s] end def []=(name, value) @cookies[name.to_s] = value @send_cookies[name.to_s] = true end def each(&block) @cookies.each(&block) end def delete(name, opts = {}) options = opts.merge(value: 'deleted', expires: Time.at(0)) self.[]=(name, options) end end end
Version data entries
7 entries across 7 versions & 1 rubygems