Class: Rack::Norman

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/norman.rb

Overview

Rack::Norman is a middleware that allows you to store a Norman datbase in a cookie.

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Norman

Returns a new instance of Norman.



8
9
10
11
# File 'lib/rack/norman.rb', line 8

def initialize(app, options = {})
  @app     = app
  @norman = ::Norman::Adapters::Cookie.new(options.merge(:sync => true))
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rack/norman.rb', line 13

def call(env)
  @norman.data = env["rack.cookies"]["norman_data"]
  @norman.load_database
  status, headers, body = @app.call(env)
  env["rack.cookies"]["norman_data"] = @norman.export_data
  [status, headers, body]
end