class RuboCop::Cop::Rails::ActionFilter
This cop enforces the consistent use of action filters methods.
The cop is configurable and the enforce the use of older something_filter methods or the newer something_action methods.
Constants
- ACTION_METHODS
- FILTER_METHODS
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 59 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/rubocop/cop/rails/action_filter.rb, line 47 def on_block(node) method, _args, _body = *node check_method_node(method) end
on_send(node)
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 53 def on_send(node) receiver, _method_name, *_args = *node check_method_node(node) if receiver.nil? end
Private Instance Methods
bad_methods()
click to toggle source
# File lib/rubocop/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/rubocop/cop/rails/action_filter.rb, line 68 def check_method_node(node) _receiver, method_name, *_args = *node return unless offending_method?(method_name) add_offense(node, :selector, format(MSG, preferred_method(method_name), method_name)) end
good_methods()
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 86 def good_methods style == :action ? ACTION_METHODS : FILTER_METHODS end
offending_method?(method_name)
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 78 def offending_method?(method_name) bad_methods.include?(method_name) end
preferred_method(method)
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 90 def preferred_method(method) good_methods[bad_methods.index(method.to_sym)] end