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 12 |
# File 'lib/monkey_forms/serializers/gzip_cookie.rb', line 6 def initialize ={} @cookie_name = [:name].to_s @domain = [:domain].to_s @secure = [:secure] @httponly = [:httponly] @path = ([:path] || '/').to_s end |
Instance Method Details
#load(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/monkey_forms/serializers/gzip_cookie.rb', line 14 def load ={} request = [:request] result = ActiveSupport::HashWithIndifferentAccess.new return result if request.blank? = request.[@cookie_name] return result if .nil? or .empty? begin result.merge!(ActiveSupport::JSON.decode(Zlib::Inflate.inflate()).stringify_keys) rescue Zlib::DataError return result end end |
#save(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/monkey_forms/serializers/gzip_cookie.rb', line 27 def save = {} attributes = [:attributes] response = [:response] = ActiveSupport::JSON.encode(attributes) = Zlib::Deflate.deflate(, Zlib::BEST_COMPRESSION) = { :value => , :httponly => @httponly, :secure => @secure, :domain => @domain, :path => @path } response.(@cookie_name, ) end |