Class: AbstractController::Callbacks::ActionFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/abstract_controller/callbacks.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(filters, conditional_key, actions) ⇒ ActionFilter

Returns a new instance of ActionFilter.



40
41
42
43
44
# File '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

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

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File '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