Class: RedisKnock::Middleware

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
# File 'lib/redis_knock/middleware.rb', line 7

def initialize(app, options = {})
  @app, @options = app, options
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/redis_knock/middleware.rb', line 5

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/redis_knock/middleware.rb', line 5

def options
  @options
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
# File 'lib/redis_knock/middleware.rb', line 11

def call(env)
  request = Rack::Request.new env
  control = RedisKnock::Control.new options
  control.allowed?(request) ? app.call(env) : limit_exceeded
end