Class: StopIt

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

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)
  response = stop?(env)

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