Class: AbstractController::Callbacks::ActionFilter

Inherits:
Object
  • Object
show all
Defined in:
actionpack/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 '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

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

Returns:

  • (Boolean)

46
47
48
49
50
51
52
53
54
55
56
57
# 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 = "The #{missing_action} action could not be found for the #{filter_names} callback on #{controller.class.name}, but it is listed in its #{@conditional_key.inspect} option"
      raise ActionNotFound.new(message, controller, missing_action)
    end
  end

  @actions.include?(controller.action_name)
end