Class: MonkeyForms::Serializers::MessagePackJson
- Inherits:
-
Object
- Object
- MonkeyForms::Serializers::MessagePackJson
- Defined in:
- lib/monkey_forms/serializers/message_pack_json.rb
Overview
Saves form as cookie as json+gzip
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MessagePackJson
constructor
A new instance of MessagePackJson.
- #load(options = {}) ⇒ Object
- #save(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MessagePackJson
Returns a new instance of MessagePackJson.
5 6 7 8 9 10 |
# File 'lib/monkey_forms/serializers/message_pack_json.rb', line 5 def initialize ={} @cookie_name = [:name] @domain = [:domain] @secure = [:secure] @httponly = [:httponly] end |
Instance Method Details
#load(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/monkey_forms/serializers/message_pack_json.rb', line 12 def load ={} request = [:request] result = ActiveSupport::HashWithIndifferentAccess.new return result if request.blank? = request.[@cookie_name] return result if .blank? result.merge!(ActiveSupport::JSON.decode(MessagePack.unpack()).stringify_keys) end |
#save(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/monkey_forms/serializers/message_pack_json.rb', line 21 def save = {} attributes = [:attributes] response = [:response] = ActiveSupport::JSON.encode(attributes).to_msgpack = { :value => , :httponly => @httponly, :secure => @secure, :domain => @domain } response.(@cookie_name, ) end |