def rate_limiting(to:, within:, by:, with:, store:, name:, scope:)
by = by.is_a?(Symbol) ? send(by) : instance_exec(&by)
cache_key = ["rate-limit", scope, name, by].compact.join(":")
count = store.increment(cache_key, 1, expires_in: within)
if count && count > to
ActiveSupport::Notifications.instrument("rate_limit.action_controller",
request: request,
count: count,
to: to,
within: within,
by: by,
name: name,
scope: scope,
cache_key: cache_key) do
with.is_a?(Symbol) ? send(with) : instance_exec(&with)
end
end
end