Sha256: ce41977e43063538784dab47089952565686b73fa7ad97d5ab4197e4befa662d
Contents?: true
Size: 1007 Bytes
Versions: 6
Compression:
Stored size: 1007 Bytes
Contents
require 'msgpack' # Saves form as cookie as json+gzip class MonkeyForms::Serializers::MessagePackJson def initialize options={} @cookie_name = options[:name] @domain = options[:domain] @secure = options[:secure] @httponly = options[:httponly] end def load options={} request = options[:request] result = ActiveSupport::HashWithIndifferentAccess.new return result if request.blank? cookie = request.cookies[@cookie_name] return result if cookie.blank? result.merge!(ActiveSupport::JSON.decode(MessagePack.unpack(cookie)).stringify_keys) end def save options = {} attributes = options[:attributes] response = options[:response] cookie_json = ActiveSupport::JSON.encode(attributes).to_msgpack cookie_hash = { :value => cookie_json, :httponly => @httponly, :secure => @secure, :domain => @domain } response.set_cookie(@cookie_name, cookie_hash) end end
Version data entries
6 entries across 6 versions & 1 rubygems