class RuboCop::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/rubocop/cop/rails/action_filter.rb, line 61 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 53 def on_block(node) check_method_node(node.send_node) end
on_send(node)
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 57 def on_send(node) check_method_node(node) unless node.receiver end
Private Instance Methods
bad_methods()
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 80 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 70 def check_method_node(node) return unless bad_methods.include?(node.method_name) add_offense(node, location: :selector) end
good_methods()
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 84 def good_methods style == :action ? ACTION_METHODS : FILTER_METHODS end
message(node)
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 76 def message(node) format(MSG, preferred_method(node.method_name), node.method_name) end
preferred_method(method)
click to toggle source
# File lib/rubocop/cop/rails/action_filter.rb, line 88 def preferred_method(method) good_methods[bad_methods.index(method.to_sym)] end