Class: GetFluxly::Rails::Middleware

Inherits:
Object
  • Object
show all
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

"gflux_anon"

Instance Method Summary collapse

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)
  cookie = env["HTTP_COOKIE"].to_s
  match = cookie.match(/(?:^|;\s*)#{COOKIE}=([^;]+)/)
  env["gflux.anonymous_id"] = match[1] if match
  @app.call(env)
end