mirror of
https://github.com/docusealco/docuseal.git
synced 2026-06-22 20:00:30 +00:00
20 lines
373 B
Ruby
20 lines
373 B
Ruby
# frozen_string_literal: true
|
|
|
|
module RateLimit
|
|
LimitApproached = Class.new(StandardError)
|
|
|
|
STORE = ActiveSupport::Cache::MemoryStore.new
|
|
|
|
module_function
|
|
|
|
def call(key, limit:, ttl:, enabled: Docuseal.multitenant?)
|
|
return true unless enabled
|
|
|
|
value = STORE.increment(key, 1, expires_in: ttl)
|
|
|
|
raise LimitApproached if value > limit
|
|
|
|
true
|
|
end
|
|
end
|