Class: Grape::Attack::Limiter
- Inherits:
-
Object
- Object
- Grape::Attack::Limiter
- Defined in:
- lib/grape/attack/limiter.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #call! ⇒ Object
-
#initialize(env, adapter = ::Grape::Attack.config.adapter) ⇒ Limiter
constructor
A new instance of Limiter.
Constructor Details
#initialize(env, adapter = ::Grape::Attack.config.adapter) ⇒ Limiter
Returns a new instance of Limiter.
10 11 12 13 14 |
# File 'lib/grape/attack/limiter.rb', line 10 def initialize(env, adapter = ::Grape::Attack.config.adapter) @request = ::Grape::Attack::Request.new(env) @adapter = adapter @counter = ::Grape::Attack::Counter.new(@request, @adapter) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/grape/attack/limiter.rb', line 8 def adapter @adapter end |
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
8 9 10 |
# File 'lib/grape/attack/limiter.rb', line 8 def counter @counter end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/grape/attack/limiter.rb', line 8 def request @request end |
Instance Method Details
#call! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/grape/attack/limiter.rb', line 16 def call! return if disable? return unless throttle? if allowed? update_counter set_rate_limit_headers else fail ::Grape::Attack::RateLimitExceededError.new("API rate limit exceeded for #{request.client_identifier}.") end end |