Sha256: 8dd1ff0c60e65481d560ae4fbc14a9ca181cf9c60ade6fcb593434f9e5e30983
Contents?: true
Size: 1.76 KB
Versions: 4
Compression:
Stored size: 1.76 KB
Contents
# encoding: utf-8 require 'rails_best_practices/reviews/review' module RailsBestPractices module Reviews # Find out unused methods in models. # # Implemenation: # # Review process: # remember all method calls, # at end, check if all defined methods are called, # if not, non called methods are unused. class RemoveUnusedMethodsInModelsReview < Review include Classable include Afterable include Callable include Exceptable interesting_nodes :command interesting_files ALL_FILES def initialize(options={}) super @model_methods = Prepares.model_methods end # skip scope and validate nodes for start_command callbacks. def skip_command_callback_nodes %w(named_scope scope validate validate_on_create validate_on_update) end # mark validate methods as used. def start_command(node) case node.message.to_s when "validate", "validate_on_create", "validate_on_update" node.arguments.all.each { |argument| mark_used(argument) } else # nothing end end # get all unused methods at the end of review process. def after_review @model_methods.get_all_unused_methods.each do |method| if !excepted?(method) && method.method_name !~ /=$/ add_error "remove unused methods (#{method.class_name}##{method.method_name})", method.file, method.line end end end protected def methods @model_methods end def internal_except_methods %w(initialize validate validate_each to_xml to_json assign_attributes after_find after_initialize).map { |method_name| "*\##{method_name}" } end end end end
Version data entries
4 entries across 4 versions & 1 rubygems