Class: CacheableFlash::Middleware

Inherits:
Object
  • Object
show all
Includes:
CookieFlash
Defined in:
lib/cacheable_flash/middleware.rb

Constant Summary collapse

FLASH_HASH_KEY =
"action_dispatch.request.flash_hash".freeze

Instance Method Summary collapse

Methods included from CookieFlash

#cookie_flash

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



8
9
10
# File 'lib/cacheable_flash/middleware.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cacheable_flash/middleware.rb', line 12

def call(env)
  status, headers, body = @app.call(env)
  env_flash = env[FLASH_HASH_KEY]

  if env_flash
    domain = CacheableFlash::Config.config[:domain]
    cookies = Rack::Request.new(env).cookies
    Rack::Utils.set_cookie_header!(headers, "flash", :value => cookie_flash(env_flash, cookies), :path => "/", :domain => domain)
  end

  [status, headers, body]
end