Module: CatForms::GzipCookie
- Defined in:
- lib/cat_forms/gzip_cookie.rb
Overview
Saves form as cookie as json+gzip
Class Method Summary collapse
Class Method Details
.load(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cat_forms/gzip_cookie.rb', line 7 def self.load ={} request = [:request] = [:cookie_name].to_s result = ActiveSupport::HashWithIndifferentAccess.new return result if request.blank? = request.[] return result if .nil? or .empty? begin result.merge!(ActiveSupport::JSON.decode(Zlib::Inflate.inflate()).stringify_keys) return result rescue Zlib::DataError return result end end |
.save(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cat_forms/gzip_cookie.rb', line 22 def self.save = {} attributes = [:attributes] response = [:response] = [:cookie_name] = ActiveSupport::JSON.encode(attributes) = Zlib::Deflate.deflate(, Zlib::BEST_COMPRESSION) = { value: , httponly: true, } response.(, ) end |