Skip to content

Instantly share code, notes, and snippets.

@diegodurs
Last active June 21, 2016 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegodurs/5618c6d1a418caaeb2d4 to your computer and use it in GitHub Desktop.
Save diegodurs/5618c6d1a418caaeb2d4 to your computer and use it in GitHub Desktop.
Rights'Up little guidelines

RightsUp Code Guidelines

Github

use dashes (-) for branches, it's easier to write than underscore (_)

Pull Requests

  • pull latest changes in the master branch git checkout master git pull origin master
  • checkout on-your-feature git checkout my-feature
  • use rebase -i master git rebase -i master
  • stash all your commits except the first one
  • write a explicit commit associated to the pivotal feature
  • in the comment write: [Finishes #id-of-the-feature-in-pivotal]

ActiveRecord

Should hold very few instance methods to get either

  • a value object (ex: territory_coverage)
  • an answer to a question (ex: executed?)

Should hold minimals scopes:

  • order dates
  # scope :newest_first
  # scope :latest_first
 
  scope :new_first # default order
  scope :newly_created_first # "newly_{attr}_first" add field inside for specific ordering
  scope :old_first
  scope :older_created_first
  
  # scope :recent
  # scope :least_recent 
  # scope :recently_sent 
  # scope :least_recently_sent-->

  # scope :chronological
  # scope :rev_chronological
  • order names
  scope :alphabetic 
  scope :rev_alphabetic
  • filter by type
  scope :from_commentable, ->(commentable) ...
  • filter by status
  • find alike: class method that retrieve one object (using first)
    • given a polymorphic association
  def self.find_by_commentable(commentable)

POROs

When we read your (Production and Test) code, we should feel that you really cared about it!

  • prefer to call a class method (other than ::new) to initialize or execute action an object when outside of the file

ex:

module RightsUp
  module Tracks
    class Destroyer
      def self.execute(track)
        new(track).destroy
      end
      ...
    end
  end
end
  • prefer to hide sub-namespaced classes with an easy external api

ex:

module RightsUp
  module Tracks
    def self.destroy(track)
      Destroyer.execute(track)
    end
  end
end
  • Methods should not hold more than 3 instructions unless it really make sense. Extract private methods until you cannot any more! (Extract until you drop).
  • Implement only what you need
  • Test only what need to be tested
  • The readability of tests is as important as the readability of production code.

Refactor, refactor, refactor...

@diegodurs
Copy link
Author

@SimonMiaou quel est ton avis sur le choix des scopes ?

@SimonMiaou
Copy link

Test procedure (on staging)

  • Rebase the staging on the master
    • git checkout staging
    • git rebase master
  • Merge you branch
    • git merge your-branch

@maximeflamant
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment