Class: Grape::Attack::Counter
- Inherits:
-
Object
- Object
- Grape::Attack::Counter
- Defined in:
- lib/grape/attack/counter.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#initialize(request, adapter) ⇒ Counter
constructor
A new instance of Counter.
- #update ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(request, adapter) ⇒ Counter
Returns a new instance of Counter.
7 8 9 10 |
# File 'lib/grape/attack/counter.rb', line 7 def initialize(request, adapter) @request = request @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/grape/attack/counter.rb', line 5 def adapter @adapter end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/grape/attack/counter.rb', line 5 def request @request end |
Instance Method Details
#update ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/grape/attack/counter.rb', line 20 def update adapter.atomically do adapter.incr(key) adapter.expire(key, ttl_in_seconds) end rescue ::Grape::Attack::StoreError end |
#value ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/grape/attack/counter.rb', line 12 def value @value ||= begin adapter.get(key).to_i rescue ::Grape::Attack::StoreError 1 end end |