Module: Raterr::Mixin
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #allowed? ⇒ Boolean
- #initialize(request, options) ⇒ Object
- #proceed ⇒ Object
- #rate_limit_exceeded ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/raterr/mixin.rb', line 4 def end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
4 5 6 |
# File 'lib/raterr/mixin.rb', line 4 def request @request end |
Instance Method Details
#allowed? ⇒ Boolean
18 19 20 21 |
# File 'lib/raterr/mixin.rb', line 18 def allowed? reset_cache if Time.now > rate_period fetch_cache[:attempts] <= max_per_period end |
#initialize(request, options) ⇒ Object
6 7 8 9 |
# File 'lib/raterr/mixin.rb', line 6 def initialize(request, ) @request = request = end |
#proceed ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/raterr/mixin.rb', line 23 def proceed attempts = fetch_cache[:attempts] + 1 set_cache(attempts) { status: 200, attempts: attempts } end |
#rate_limit_exceeded ⇒ Object
11 12 13 14 15 16 |
# File 'lib/raterr/mixin.rb', line 11 def rate_limit_exceeded { status: [:code] || Raterr::DEFAULTS[:code], text: Raterr::DEFAULTS[:message] % { time: try_after } } end |