Class: GetFluxly::Rails::Middleware
- Inherits:
-
Object
- Object
- GetFluxly::Rails::Middleware
- Defined in:
- lib/getfluxly/rails.rb
Overview
Tiny Rack middleware: extracts gflux_anonymous_id from the request cookie and attaches it as request.env so controller code can resume the browser session for server-side track() calls. Wire it from config/application.rb:
require "getfluxly/rails"
config.middleware.use GetFluxly::Rails::Middleware
Constant Summary collapse
- COOKIE =
"gflux_anon"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
45 46 47 |
# File 'lib/getfluxly/rails.rb', line 45 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/getfluxly/rails.rb', line 49 def call(env) = env["HTTP_COOKIE"].to_s match = .match(/(?:^|;\s*)#{COOKIE}=([^;]+)/) env["gflux.anonymous_id"] = match[1] if match @app.call(env) end |