Skip to content

Instantly share code, notes, and snippets.

View serodriguez68's full-sized avatar

Sergio Rodríguez serodriguez68

View GitHub Profile
@serodriguez68
serodriguez68 / 1_poodir_notes.md
Last active June 8, 2016 01:59 — forked from speric/poodir-notes.md
Notes From "Practical Object-Oriented Design In Ruby" by Sandi Metz

Practical Object-Oriented Design in Ruby - Notes

Notes by: Sergio Rodriguez Book by: Sandi Metz


Chapter 1 - Object Oriented Design

Why Design?

  • Changes in applications are unavoidable.
  • Change is hard because of the dependencies between objects
  • The sender of the message knows things about the receiver
@serodriguez68
serodriguez68 / rails_heroku_reset_itself.md
Last active January 18, 2019 07:07
How to make a Rails application rails db:reset itself on Heroku

How to make a Rails application rails db:reset itself on Heroku

Imagine you have some type of demo that needs to reset itself once a day.

  1. Install the Database Cleaner Gem and make sure you make it available for the production environment.

  2. Create a lib/tasks/scheduler.rake file that looks similar to this

desc "This task is called by the Heroku scheduler add-on to reset the demo"
task :reset_demo => :environment do
  puts "Cleaning Up The DB..."
@serodriguez68
serodriguez68 / dependency_injection_overriding_new.md
Last active April 18, 2020 10:44
Dependency Injection with defaults in Ruby by overriding the new method

Dependency Injection with defaults in Ruby by overriding the new method

This technique his heavilly inspired by Tom Dalling's Dependency Injection Containers vs Hard-coded Constants article. In particular, it proposes an alternative implementation of his "Hybrid Approach" using a build class method.

The main problems with Tom's implementation using build

  • It introduces a new way of instantiating objects via the .build method. This new API requires other developers to be aware that they must use .build if they want an instance of the object with default dependencies.
  • Following from the point above, in cases where we want to use cascading default dependencies, we must remember to use the dependencies .build method to benefit from their default behaviour.

Our approach: overriding .new

@serodriguez68
serodriguez68 / objects_that_be_vs_objects_that_do.md
Last active April 18, 2020 10:51
What parameters should go in the initialisation method? Objects that "be" VS Objects that "do"

What parameters should go in the initialisation method? Objects that "be" VS Objects that "do"

Tim Riley has a great rule of thumb for classifying objects and deciding what parameters should be part of the class' attributes (state) VS which should be provided as arguments to the methods of that class.

There are 2 types of Objects: Objects that "be" and Objects that "do".

Objects that "be"

If you say "this object IS a dog", then you are dealing with an object that "be".

The job of these objects are to represent data in our application. They hold data in their state and therefore we must

@serodriguez68
serodriguez68 / Rails 6 Guides Encrypted Credentials Documentation Gaps.md
Last active May 22, 2020 07:26
A break down of the documentation gaps that exist in Rails' 6.0.3.1 guides related to encrypted credentials.