Module: ActionController

Defined in:
runtime/action_controller/current.rb,
runtime/action_controller/api.rbs,
runtime/action_controller/current.rbs,
runtime/action_controller/exceptions.rbs,
runtime/action_controller/http_authentication.rbs,
runtime/action_controller/params.rbs,
runtime/action_controller/rate_limiter.rbs,
runtime/action_controller/api.rb,
runtime/action_controller/exceptions.rb,
runtime/action_controller/http_authentication.rb,
runtime/action_controller/json_render.rb,
runtime/action_controller/params.rb,
runtime/action_controller/rate_limiter.rb

Overview

The question behind rate_limit to: 10, within: 3.minutes: has this key been seen more than to times in the current window?

exceeded?  =  the window's count, after this request, > to

The count lives in Snails.cache under the key the lowering builds — rate-limit:<controller_path>[:<name>]:<by> — and the window is the entry's TTL: the first request in a window writes it with within seconds to live, and every later one increments it until it expires.

Called from the private method the rate_limit lowering synthesizes; the with: block — what to do when the answer is yes — is the app's, and runs in that method.

Defined Under Namespace

Modules: Current, HttpAuthentication, JsonRender, Params, RateLimiter Classes: API, ParameterMissing, UnknownFormat, UnpermittedParameters

Constant Summary collapse

JSON_CONTENT_TYPE =

The content type render json: answers when the caller names none — byte-identical to the scaffold's JSON_TYPE literal, so moving a call to render json: keeps the header unchanged.

"application/json; charset=utf-8"
JSON_NOT_GIVEN =

What json: holds when the caller passed no json: keyword. Ruby cannot express "keyword omitted", so absence rides a dedicated object rather than nil: render json: nil must still encode to null, while a bare render() must fail loudly. Nothing a caller can pass equals it, so no payload's == hijacks the test.

Object.new