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