Sha256: 9d1f906be98577d71fb89e2d686fcbdfff527529413ba3c4abab421fd0d5f4e3

Contents?: true

Size: 854 Bytes

Versions: 2

Compression:

Stored size: 854 Bytes

Contents

require 'json'

module CacheableFlash
  if defined?(Rails) && ::Rails::VERSION::MAJOR == 3
    require 'cacheable_flash/middleware'
    require 'cacheable_flash/engine' if ::Rails::VERSION::MINOR >= 1
    require 'cacheable_flash/railtie'
  else 
    # For older rails use generator
  end

  require 'cacheable_flash/cookie_flash'
  include CookieFlash

  def self.included(base)
    #base must define around_filter, as in Rails
    base.around_filter :write_flash_to_cookie
  end

  def write_flash_to_cookie
    yield if block_given?

    # Base must define cookies, as in Rails
    cookies['flash'] = cookie_flash(flash, cookies)
    # Base must define flash, as in Rails
    # TODO: Does not support flash.now feature of the FlashHash in Rails, 
    #       because flashes are only removed from cookies when they are used.
    flash.clear
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cacheable_flash-0.2.9 lib/cacheable_flash.rb
cacheable_flash-0.2.8 lib/cacheable_flash.rb