module Rack
  class Pesticide
    def initialize(app)
      @app = app
    end

    def call(env)
      if pest?(env)
        forbidden
      else
        @app.call(env)
      end
    end

    private

    def forbidden
      [403, {"Content-Type" => "text/plain"}, ["Semalt, be gone!\n"]]
    end

    def pest?(env)
      referer = env['HTTP_REFERER'] || ''
      referer =~ /semalt\.com\/crawler\.php/
    end
  end
end

module Rack
  class Pesticide
    def initialize(app)
      @app = app
    end

    def call(env)
      if pest?(env)
        forbidden
      else
        @app.call(env)
      end
    end

    private

    def forbidden
      [403, {"Content-Type" => "text/plain"}, ["Pest, be gone!\n"]]
    end

    def pest?(env)
      pests = [/semalt\.com\/crawler\.php/]
      referer = env['HTTP_REFERER'] || ''
      pests.map { |p| referer =~ p }.any?
    end
  end
end

Rewrite pest? to check list of possible referrers
Rewrite pest? to check list of possible referrers
