Extract Value Object

One more on our clean code series (I think every post I make is about clean code, at least I do my best). The last one was about the Null Object Pattern. Today will be about the Extract Value Object. class SummaryCard attr_accessor :reviews def initialize(attributes = {}) @stars = attributes.fetch(:stars, nil) @reviews ||= review_scores […]

Read More Extract Value Object

Null Object Pattern

Another one, follows from the clean code series I am making. The last post was about Extract Class. Today we are going to talk about the Null Object Pattern and how we can implement it in ruby. Below we have an example of a music platform subscription pattern with the classes: class User include ActiveModel::Model […]

Read More Null Object Pattern

JSONb with Ruby on Rails

I needed to get something from the database in my job. I tried the current query using PSequel and it gave an error. SELECT * FROM declarations WHERE data->>’some_data’ IS NOT NULL; The way I got the results was through the console with the following: bundle exec rails console declarations_ids = [] Declaration.find_each do |d| […]

Read More JSONb with Ruby on Rails

find in Ruby

So, I was working and found this nice idea on the code base about using the find for mail dunnings. This will be simplified to the max in order to keep the post short. In the Payments table we have the following columns: payment_reminder_sent_at first_dunning_sent_at last_dunning_sent_at What this code do is, find in the current […]

Read More find in Ruby

Holidays helper in Ruby on Rails

Today, while doing a calendar I found a module on Rails called Holidays. I will use the Rails console to demonstrate: bundle exec rails c Loading development environment (Rails 5.0.1) [1] pry(main)> Holidays.on(Date.tomorrow, :pt) => [{:date=>Wed, 01 Nov 2017, :name=>”Dia de Todos-os-Santos”, :regions=>[:pt]}] [2] pry(main)> Holidays.on(Date.today, :pt) => []

Read More Holidays helper in Ruby on Rails