class RubbyCop::Cop::Rails::ActionFilter

This cop enforces the consistent use of action filter methods.

The cop is configurable and can enforce the use of the older something_filter methods or the newer something_action methods.

If the TargetRailsVersion is set to less than 4.0, the cop will enforce the use of filter methods.

Constants

ACTION_METHODS
FILTER_METHODS
MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubbycop/cop/rails/action_filter.rb, line 63
def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.selector,
                      preferred_method(node.loc.selector.source).to_s)
  end
end
on_block(node) click to toggle source
# File lib/rubbycop/cop/rails/action_filter.rb, line 53
def on_block(node)
  method, _args, _body = *node

  check_method_node(method)
end
on_send(node) click to toggle source
# File lib/rubbycop/cop/rails/action_filter.rb, line 59
def on_send(node)
  check_method_node(node) unless node.receiver
end

Private Instance Methods

bad_methods() click to toggle source
# File lib/rubbycop/cop/rails/action_filter.rb, line 82
def bad_methods
  style == :action ? FILTER_METHODS : ACTION_METHODS
end
check_method_node(node) click to toggle source
# File lib/rubbycop/cop/rails/action_filter.rb, line 72
def check_method_node(node)
  return unless bad_methods.include?(node.method_name)

  add_offense(node, :selector)
end
good_methods() click to toggle source
# File lib/rubbycop/cop/rails/action_filter.rb, line 86
def good_methods
  style == :action ? ACTION_METHODS : FILTER_METHODS
end
message(node) click to toggle source
# File lib/rubbycop/cop/rails/action_filter.rb, line 78
def message(node)
  format(MSG, preferred_method(node.method_name), node.method_name)
end
preferred_method(method) click to toggle source
# File lib/rubbycop/cop/rails/action_filter.rb, line 90
def preferred_method(method)
  good_methods[bad_methods.index(method.to_sym)]
end