class Makara::Middleware

Public Class Methods

new(app, cookie_options = {}) click to toggle source
# File lib/makara/middleware.rb, line 6
def initialize(app, cookie_options = {})
  @app = app
  @cookie_options = cookie_options
end

Public Instance Methods

call(env) click to toggle source
# File lib/makara/middleware.rb, line 11
def call(env)
  return @app.call(env) if ignore_request?(env)

  set_current_context(env)

  status, headers, body = @app.call(env)
  store_new_context(headers)

  [status, headers, body]
end

Protected Instance Methods

ignore_request?(env) click to toggle source

ignore asset paths consider allowing a filter proc to be provided in an initializer

# File lib/makara/middleware.rb, line 35
def ignore_request?(env)
  if defined?(Rails) && Rails.try(:application).try(:config).try(:assets).try(:prefix)
    if env['PATH_INFO'].to_s =~ /^#{Rails.application.config.assets.prefix}/
      return true
    end
  end
  false
end
set_current_context(env) click to toggle source
# File lib/makara/middleware.rb, line 24
def set_current_context(env)
  context_data = Makara::Cookie.fetch(Rack::Request.new(env))
  Makara::Context.set_current(context_data)
end
store_new_context(headers) click to toggle source
# File lib/makara/middleware.rb, line 29
def store_new_context(headers)
  Makara::Cookie.store(Makara::Context.next, headers, @cookie_options)
end