Extract method

Following the clean code series, today we will talk about the extract method. This looks a little like the replace variable with query but a bit different. The extract method usually is to remove the extra code lines from a method, as to make it more readable and understand what it does when looking at […]

Read More Extract method

Replace Variable with Query

In the last blog post I showed a way to simply reading the code by using variables explaining what they are doing. Today we will start from where we finished and extract the variables to methods. class Product TAX = 0.05 def initialize(amount:, discount_percentage: 0) @amount = amount @discount_percentage = discount_percentage end def total tax_amount […]

Read More Replace Variable with Query

Explaining variable

I was studying a few weeks back and did a refactoring trail in ThoughBot’s Upcase screen casts. Some of the naming they used were outlandish to me and most of the things there I already knew by learning on the job and watching videos or reading blog posts. One of the things that we can […]

Read More Explaining variable

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

HTTP with ruby

In my job we recently decided to use an email management tool called getResponse which I started to build the adapter to user with its API. One of the first things I did was to test the creation of an email with curl: curl -X POST https://api3.getresponse360.pl/v3/contacts -d ‘{“email”: “adnilson@frontline.cv”, “campaign”: { “campaignId”: “G” } […]

Read More HTTP with 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