Sha256: 8b4e4d33dfd92ca197721256bd81547abfbe4120fa1fb3f08513808bd943a690

Contents?: true

Size: 1004 Bytes

Versions: 1

Compression:

Stored size: 1004 Bytes

Contents

module CacheableFlash
  module CookieFlash
    def cookie_flash(flash, cookies)
      cflash = (JSON.parse(cookies['flash']) if cookies['flash']) || {} rescue {}
      flash.each do |key, value|
        # Since v0.3.0 only escaping strings
        if value.kind_of?(String)
          value = ERB::Util.html_escape(value) unless value.html_safe?
        end
        skey = key.to_s
        # This allows any data type to be stored in the cookie; important for using an array as the value with
        # stackable_flash
        if cflash[skey].kind_of?(Array) # Already Stackable!!!
          if value.kind_of?(Array)
            cflash[skey] += value # Add the values from the other array, which is already a stackable flash
          else
            cflash[skey] << value
          end
        else
          cflash[skey] = value
        end
      end
      # I have forgotten why the gsub + matters, so NOTE: to future self: document weird shit.
      cflash.to_json.gsub("+", "%2B")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cacheable_flash-0.3.1 lib/cacheable_flash/cookie_flash.rb