Sha256: eae818174ddcc926eec5b27b4efb12bfe72b63dd86235c024f330839edaae261
Contents?: true
Size: 846 Bytes
Versions: 17
Compression:
Stored size: 846 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
17 entries across 17 versions & 2 rubygems