123456789_123456789_123456789_123456789_123456789_

Class: AbstractController::Callbacks::ActionFilter

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/abstract_controller/callbacks.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(filters, conditional_key, actions) ⇒ ActionFilter

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/callbacks.rb', line 40

def initialize(filters, conditional_key, actions)
  @filters = filters.to_a
  @conditional_key = conditional_key
  @actions = Array(actions).map(&:to_s).to_set
end

Instance Method Details

#after(controller)

Alias for #match?.

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/callbacks.rb', line 69

alias after  match?

#around(controller)

Alias for #match?.

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/callbacks.rb', line 71

alias around match?

#before(controller)

Alias for #match?.

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/callbacks.rb', line 70

alias before match?

#match?(controller) ⇒ Boolean Also known as: #after, #before, #around

[ GitHub ]

  
# File 'actionpack/lib/abstract_controller/callbacks.rb', line 46

def match?(controller)
  if controller.raise_on_missing_callback_actions
    missing_action = @actions.find { |action| !controller.available_action?(action) }
    if missing_action
      filter_names = @filters.length == 1 ? @filters.first.inspect : @filters.inspect

      message = <<~MSG
        The #{missing_action} action could not be found for the #{filter_names}
        callback on #{controller.class.name}, but it is listed in the controller's
        #{@conditional_key.inspect} option.

        Raising for missing callback actions is a new default in Rails 7.1, if you'd
        like to turn this off you can delete the option from the environment configurations
        or set `config.action_controller.raise_on_missing_callback_actions` to `false`.
      MSG

      raise ActionNotFound.new(message, controller, missing_action)
    end
  end

  @actions.include?(controller.action_name)
end