Sha256: 7dc80f1de411c6846946f676a3c2f42978a0e1dbfe9b59cf24f5954eb3987925
Contents?: true
Size: 868 Bytes
Versions: 16
Compression:
Stored size: 868 Bytes
Contents
require "json" module Split module Persistence class CookieAdapter EXPIRES = Time.now + 31536000 # One year from now def initialize(context) @cookies = context.send(:cookies) end def [](key) hash[key] end def []=(key, value) set_cookie(hash.merge(key => value)) end def delete(key) set_cookie(hash.tap { |h| h.delete(key) }) end def keys hash.keys end private def set_cookie(value) @cookies[:split] = { :value => JSON.generate(value), :expires => EXPIRES } end def hash if @cookies[:split] begin JSON.parse(@cookies[:split]) rescue JSON::ParserError {} end else {} end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems