Sha256: 3106f64f10eb4d623a730d7a61abcbdb6dc2079424d83373c0bacbd0cdb7aec3

Contents?: true

Size: 635 Bytes

Versions: 1

Compression:

Stored size: 635 Bytes

Contents

class StopIt

  class << self
    def stop &block
      if block_given?
        @stop = block
      else
        @stop
      end
    end
  end

  def initialize(app)
    @app = app
  end

  def call(env)
    response = stop?(env)

    if response == true
      [200, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
    elsif response == false
      @app.call(env)
    else
      response
    end
  end

  private

  def stop?(env)
    StopIt.stop && StopIt.stop.call(
      env["PATH_INFO"],
      env["REMOTE_ADDR"],
      env["QUERY_STRING"],
      env["REQUEST_METHOD"],
      env["HTTP_USER_AGENT"]
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stop_it-1.0.0 lib/stop_it.rb