Class: Rack::API::Middleware::Limit
- Inherits:
-
Object
- Object
- Rack::API::Middleware::Limit
- Defined in:
- lib/rack/api/middleware/limit.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Limit
constructor
A new instance of Limit.
Constructor Details
#initialize(app, options = {}) ⇒ Limit
Returns a new instance of Limit.
7 8 9 10 11 12 13 14 |
# File 'lib/rack/api/middleware/limit.rb', line 7 def initialize(app, = {}) @app = app @options = { :limit => 60, :key => "REMOTE_ADDR", :with => Redis.new }.merge() end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/rack/api/middleware/limit.rb', line 5 def env @env end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/rack/api/middleware/limit.rb', line 5 def @options end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/api/middleware/limit.rb', line 16 def call(env) @env = env if @app.call(env) else [503, {"Content-Type" => "text/plain"}, ["Over Rate Limit."]] end rescue Exception => e @app.call(env) end |