Class: StopIt

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

Overview

Middleware to block unwanted requests to a Rake app

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ StopIt

Returns a new instance of StopIt.



13
14
15
# File 'lib/stop_it.rb', line 13

def initialize(app)
  @app = app
end

Class Method Details

.stop(&block) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/stop_it.rb', line 4

def stop(&block)
  if block_given?
    @stop = block
  else
    @stop
  end
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stop_it.rb', line 17

def call(env)
  should_be_stopped = request_should_be_stopped?(env)

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