Giter VIP home page Giter VIP logo

rails_best_practices's Introduction

rails_best_practices

rails_best_practices is a code metric tool to check the quality of rails codes.


Usage

At the root directory of rails app


rails_best_practices .

notice the period at the end, it can be the relative or absolute path of your rails app.

And default rails_best_practices will do parse codes in vendor, spec, test and stories directories. If you need, see the command options:


$ rails_best_practices -h
Usage: rails_best_practices [options]
    -d, --debug                      Debug mode
        --vendor                     include vendor files
        --spec                       include spec files
        --test                       include test files
        --stories                    include stories files
    -x, --exclude PATTERNS           Don't analyze files matching a pattern
                                     (comma-separated regexp list)
    -v, --version                    Show this version
    -h, --help                       Show this message

Helpful links

Homepage: http://rails-bestpractices.com
Repository: http://github.com/flyerhzm/rails_best_practices
Wiki: http://github.com/flyerhzm/rails_best_practices/wiki


Install


gem install rails_best_practices

Issue

If you got NoMethodError or any syntax error, you should use debug mode to detect which file rails_best_practices is parsing and getting the error.


rails_best_practices -d .

Then give me the error stack and the source code of the file that rails_best_practices is parsing error.

http://github.com/flyerhzm/rails_best_practices/issues


Customize Configuration

Copy rails_best_practices.yml in the root directory of rails_best_practices gem to config directory
Now you can customize the configuration, the default configuration is as follows:


MoveFinderToNamedScopeCheck: { }
UseModelAssociationCheck: { }
UseScopeAccessCheck: { }
AddModelVirtualAttributeCheck: { }
ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
MoveModelLogicIntoModelCheck: { called_count: 4 }
OveruseRouteCustomizationsCheck: { customize_count: 3 }
NeedlessDeepNestingCheck: { nested_count: 2 }
NotUseDefaultRouteCheck: {  }
KeepFindersOnTheirOwnModelCheck: { }
LawOfDemeterCheck: { }
UseObserverCheck: { }
IsolateSeedDataCheck: { }
AlwaysAddDbIndexCheck: { }
UseBeforeFilterCheck: { }
MoveCodeIntoControllerCheck: { }
MoveCodeIntoModelCheck: { }
MoveCodeIntoHelperCheck: { array_count: 3 }
ReplaceInstanceVariableWithLocalVariableCheck: { }
DryBundlerInCapistranoCheck: { }
UseSayWithTimeInMigrationsCheck: { }
UseQueryAttributeCheck: { }

Implementation

  • Move code from Controller to Model
    1. Move finder to named_scope (rails2 only)
    2. Use model association
    3. Use scope access
    4. Add model virtual attribute
    5. Replace Complex Creation with Factory Method
    6. Move Model Logic into the Model
  • RESTful Conventions
    1. Overuse route customizations
    2. Needless deep nesting
    3. Not use default route
  • Model
    1. Keep Finders on Their Own Model (rails2 only)
    2. the Law of Demeter
    3. Use Observer
    4. Use Query Attribute
  • Migration
    1. Isolating Seed Data
    2. Always add DB index
    3. Use Say with Time in Migrations
  • Controller
    1. Use before_filter
  • View
    1. Move code into controller
    2. Move code into model
    3. Move code into helper
    4. Replace instance variable with local variable
  • Deployment
    1. Dry bundler in capistrano

Contribute

If you want to add your rails best practices into the gem, please post your best practices on http://rails-bestpractices.com


Contact

Follow us on twitter: http://twitter.com/railsbp
Send us email: [email protected]


Copyright © 2010 Richard Huang ([email protected]), released under the MIT license

rails_best_practices's People

Contributors

flyerhzm avatar gravis avatar madcowley avatar recurser avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.