class Napa::Ext::Poison

Constants

MATCHER

Attributes

app[R]

Public Class Methods

new(app) click to toggle source
# File lib/napa/ext/poison.rb, line 6
def initialize app
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/napa/ext/poison.rb, line 10
def call env
  pill = pill_from env
  if pill
    handler_for(pill).call env
  else
    app.call env
  end
end

Private Instance Methods

handler_for(pill) click to toggle source
# File lib/napa/ext/poison.rb, line 29
def handler_for pill
  Rack::Auth::Basic.new PoisonHandler.new(pill) do |username, password|
    ENV['POISON_CREDENTIAL'] &&
      [username, password] == ENV['POISON_CREDENTIAL'].split(':')
  end
end
pill_from(env) click to toggle source
# File lib/napa/ext/poison.rb, line 23
def pill_from env
  result = MATCHER.match env['PATH_INFO']

  result[:pill] if result
end