# encoding: utf-8 #-- # Copyright (c) 2010 Richard Huang (flyerhzm@gmail.com) # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ require 'rubygems' require 'progressbar' require 'colored' require 'rails_best_practices/checks' require 'rails_best_practices/core' # RailsBestPractices helps you to analyze your rails code, according to best practices on http://rails-bestpractices. # if it finds any violatioins to best practices, it will give you some readable suggestions. # # The analysis process is partitioned into two parts, # # 1. prepare process, it checks only model and mailer files, do some preparations, such as remember model names and associations. # 2. review process, it checks all files, according to configuration, it really check if codes violate the best practices, if so, remember the violations. # # After analyzing, output the violations. module RailsBestPractices DEFAULT_CONFIG = File.join(File.dirname(__FILE__), "..", "rails_best_practices.yml") class < b end } end # ignore specific files. # # @param [Array] files # @param [Regexp] pattern files match the pattern will be ignored # @return [Array] files that not match the pattern def file_ignore files, pattern files.reject { |file| file.index(pattern) } end # output errors if exist. def output_errors @runner.errors.each { |error| puts error.to_s.red } puts "\nPlease go to http://rails-bestpractices.com to see more useful Rails Best Practices.".green if @runner.errors.empty? puts "\nNo error found. Cool!".green else puts "\nFound #{@runner.errors.size} errors.".red end end end end