Class: RateLimitedService::RateLimiterScopedAndKeyed
- Inherits:
-
Object
- Object
- RateLimitedService::RateLimiterScopedAndKeyed
- Defined in:
- app/services/concerns/rate_limited_service.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#rate_limiter ⇒ Object
readonly
Returns the value of attribute rate_limiter.
Instance Method Summary collapse
-
#initialize(key:, opts:, rate_limiter:) ⇒ RateLimiterScopedAndKeyed
constructor
A new instance of RateLimiterScopedAndKeyed.
- #rate_limit!(service) ⇒ Object
Constructor Details
#initialize(key:, opts:, rate_limiter:) ⇒ RateLimiterScopedAndKeyed
Returns a new instance of RateLimiterScopedAndKeyed.
31 32 33 34 35 |
# File 'app/services/concerns/rate_limited_service.rb', line 31 def initialize(key:, opts:, rate_limiter:) @key = key @opts = opts @rate_limiter = rate_limiter end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
29 30 31 |
# File 'app/services/concerns/rate_limited_service.rb', line 29 def key @key end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
29 30 31 |
# File 'app/services/concerns/rate_limited_service.rb', line 29 def opts @opts end |
#rate_limiter ⇒ Object (readonly)
Returns the value of attribute rate_limiter.
29 30 31 |
# File 'app/services/concerns/rate_limited_service.rb', line 29 def rate_limiter @rate_limiter end |
Instance Method Details
#rate_limit!(service) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/services/concerns/rate_limited_service.rb', line 37 def rate_limit!(service) evaluated_scope = evaluated_scope_for(service) if rate_limiter.throttled?(key, **opts.merge(scope: evaluated_scope.values, users_allowlist: users_allowlist)) raise RateLimitedError.new(key: key, rate_limiter: rate_limiter), _('This endpoint has been requested too many times. Try again later.') end end |