Class: Rack::CookieMonster

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

Defined Under Namespace

Classes: Hungry

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = nil) ⇒ CookieMonster

Returns a new instance of CookieMonster.



39
40
41
42
# File 'lib/rack/cookie_monster.rb', line 39

def initialize(app, opts=nil)
  @app = app
  @config = opts.nil? ? self.class : CookieMonsterConfig.new(opts)
end

Class Method Details

.configure {|@config| ... } ⇒ Object

Yields:

  • (@config)


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

def configure
  @config ||= CookieMonsterConfig.new
  yield(@config)
  @configured = true
end

.configure_for_railsObject



23
24
25
26
27
28
29
# File 'lib/rack/cookie_monster.rb', line 23

def configure_for_rails
  ensure_monster_configured!
  ActionController::Dispatcher.middleware.insert_before(
    ActionController::Base.session_store,
    self
  )
end

.cookiesObject



18
19
20
21
# File 'lib/rack/cookie_monster.rb', line 18

def cookies
  ensure_monster_configured!
  @config.cookies
end

.snackersObject



13
14
15
16
# File 'lib/rack/cookie_monster.rb', line 13

def snackers
  ensure_monster_configured!
  @config.snackers
end

Instance Method Details

#call(env) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/rack/cookie_monster.rb', line 44

def call(env)
  shares_with(env["HTTP_USER_AGENT"]) do
    request = ::Rack::Request.new(env)
    eat_cookies!(env, request)
  end
  @app.call(env)
end