class Rack::Pesticide
Constants
- VERSION
Public Class Methods
new(app)
click to toggle source
# File lib/rack/pesticide.rb, line 3 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/pesticide.rb, line 7 def call(env) if pest?(env) forbidden else @app.call(env) end end
Private Instance Methods
forbidden()
click to toggle source
# File lib/rack/pesticide.rb, line 17 def forbidden [403, {"Content-Type" => "text/plain"}, ["Pest, be gone!\r\n"]] end
load_pests()
click to toggle source
# File lib/rack/pesticide.rb, line 30 def load_pests path = ::File.expand_path('../../../data/pests.txt', __FILE__) ::File.open(path, 'r') do |fh| fh.each_line.map { |line| /#{line.chomp}/ } end end
pest?(env)
click to toggle source
# File lib/rack/pesticide.rb, line 21 def pest?(env) referer = env['HTTP_REFERER'] || '' pests.map { |p| referer =~ p }.any? end
pests()
click to toggle source
# File lib/rack/pesticide.rb, line 26 def pests @pests ||= load_pests end