module Cutoff::Rails::Controller

Rails controller integration

Public Instance Methods

cutoff(seconds, options = {}) click to toggle source

Set a cutoff for the controller

Can be called multiple times with different options to configure cutoffs for various conditions. If multiple conditions match a given controller, the last applied cutoff “wins”.

@example

class ApplicationController
  # Apply a global maximum
  cutoff 30
end

class UsersController < ApplicationController
  # Override the base time limit
  cutoff 5.0
  cutoff 3.0, only: :show
  cutoff 7, if: :signed_in
end

@param seconds [Float, Integer] The allowed seconds for a controller

action

@param options [Hash] Options to pass to `around_action`. For example,

pass `:only`, `:except`, `:if`, to limit the scope of the cutoff.
# File lib/cutoff/rails/controller.rb, line 32
def cutoff(seconds, options = {})
  prepend_around_action(options) do |_controller, action|
    next action.call if @cutoff_wrapped

    begin
      @cutoff_wrapped = true
      Cutoff.wrap(seconds, &action)
    ensure
      @cutoff_wrapped = false
    end
  end
end