Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Live with Rails

Live with Rails

My life with Rails and how I avoid it.

Oursky Limited

April 09, 2013
Tweet

More Decks by Oursky Limited

Other Decks in Programming

Transcript

  1. Live with Rails
    And avoid Rails
    Rick Mak, Apr 2013
    Tuesday, 9 April, 13

    View full-size slide

  2. Fact
    Rails is fast on creating MVP
    Rails is fast on creating Restful API
    Rails has many stackoverflow articles.
    Tuesday, 9 April, 13

    View full-size slide

  3. Getting big and
    getting away
    Rails is slow
    Test is Rails is stupidly slow
    EdwinKwok says Rails is Architecture, not
    Entity: https://speakerdeck.com/oursky/
    clean-code?slide=50
    Tuesday, 9 April, 13

    View full-size slide

  4. Heaven & Hell
    Tuesday, 9 April, 13

    View full-size slide

  5. Requirement
    Both Project and User have quota
    Project may have owner
    If a project has owner, ignore project quota
    If a project owner quota exceed, consider
    project quota.
    User can upgrade his quota
    Tuesday, 9 April, 13

    View full-size slide

  6. Your Rails model
    Project
    User
    Project Quota
    User Quota
    Tuesday, 9 April, 13

    View full-size slide

  7. Where is the
    Logic?
    Tuesday, 9 April, 13

    View full-size slide

  8. Fat ActiveRecords
    Tuesday, 9 April, 13

    View full-size slide

  9. ActiveSupport::Concern
    http://blog.codeclimate.com/blog/2012/10/17/7-ways-
    to-decompose-fat-activerecord-models/
    “Any application with an app/concerns
    directory is concerning.”
    Tuesday, 9 April, 13

    View full-size slide

  10. No Time!
    I really need test case when it about $money$
    I really need test case when I follow up fat AR.
    Tuesday, 9 April, 13

    View full-size slide

  11. No more free project
    Boss
    Tuesday, 9 April, 13

    View full-size slide

  12. Where to change
    Tuesday, 9 April, 13

    View full-size slide

  13. Standalone project
    payment
    Boss
    Tuesday, 9 April, 13

    View full-size slide

  14. My life
    Tuesday, 9 April, 13

    View full-size slide

  15. Introduce Quota
    Project Quota & User Quota is for storage only
    All logic belongs to Quota
    Tuesday, 9 April, 13

    View full-size slide

  16. Quota is not AR
    It test against its rspec, it is fast.
    One place to edit
    Tuesday, 9 April, 13

    View full-size slide

  17. Result
    Tuesday, 9 April, 13

    View full-size slide

  18. Architecture matters
    Around 5 ticket about resource protection
    against expire/archive/non-owner will
    become trivial to fix after introducing Quota.
    Rails architecture is just a guideline.
    Tuesday, 9 April, 13

    View full-size slide