#​567 — August 26, 2021

Read on the Web

Ruby Weekly

Privacy-Aware Rails Consoles with console1984 and audits1984 — Basecamp created console1984 to protect sensitive/encrypted data in a console connected to production. The audits1984 gem provides a UI (Rails engine) to examine the logs created by console1984.

Jorge Manrubia (Basecamp)

A Tour of Twist — Twist is a Hanami-inspired Ruby application that Ryan uses to expose his nascent books to reviewers for notes and suggestions. It uses dry-rb components, ROM, and many off-the-Rails-path items.

Ryan Bigg

Free eBook: Effective Indexing in Postgres — Learn how to create the best Postgres index for your queries. We provide a deep dive into index types, operators, data types and more. Creating the right indexes can often improve your query performance by 10x or even 100x.

pganalyze sponsor

QUICK BITS:

▶  Decomposing a Massive Rails Monolith with Shopify's Kirsten Westeinde — We’re not all going to have the opportunity to decompose a giant monolith, so listening to how Shopify handled it with tools, practices, and trial and error, along with what they learned, is fascinating.

Sourcegraph podcast

Jobs

Senior Software Engineer (Remote in the US) — Snapdocs is now a Unicorn with a $1.5B+ valuation. We’re a SaaS product disrupting the mortgage and real-estate industry. Join our growing distributed team. ROR, Go, Postgres, React, AWS.
Snapdocs

Full Stack Engineer (Rails, New York) — Dovetale helps Shopify merchants like KontrolFreek and Italic grow their creator community. Built in NYC and backed by Uber founders.
Dovetale

Find Ruby Jobs Through Hired — Create a profile on Hired to connect with hiring managers at growing startups and Fortune 500 companies. It's free for job-seekers.
Hired

📕 Articles & Tutorials

Responsible Monkeypatching in Ruby — Yes, yes…we all understand that monkeypatching isn’t always the best idea but it’s sometimes unavoidable, so having a defensive (and quite involved) approach can save your bananas later.

Cameron Dutro (AppSignal)

An Introduction to jq for JSON Wrangling — jq is a fast, C-powered command-line utility to parse, sort, filter, and do just about anything with JSON data. Adam’s post is now the place to go to to remember jq syntax instead of Googling it.

Adam Gordon Bell

Submitting Many ActionMail Jobs at Once with Sidekiq — ActionJob does not expose a bulk submission method and, by default, will create loads of connections when you submit many jobs, but we (and Wander) can fix that.

Wander Hillen

How to Send Emails with Ruby — In this tutorial, we’ll show you the way to add email functionality to your Ruby app focusing on transactional triggers.

Courier sponsor

Notes on Retrying All Jobs with ActiveJob retry_on — An argument for using ActiveJob#retry_on for all errors (even if DHH says that’s bad) and how to get it going with Resque.

Jonathan Rochkind

Better Ruby Gemfile Security: A Step-by-Step Guide using Snyk — This is more about scanning popular Ruby gems and listing their vulnerabilities along with how to address each one.

Snyk

Run RuboCop on git commit with Overcommit — A simple tip. Overcommit is a git hook manager.

Prabin Poudel

▶  Brittany and Jemma Talk Life Stories and Some of Their Favorite Things — The Ruby on Rails Podcast takes a cosier, more personal tone this week with Jemma (who writes our Tip of the Week!) and Brittany (the main host) talking about how Jemma is joining Shopify (congrats!), their favorite developer tools, and the WNB.rb Ruby user group.

The Ruby on Rails Podcast podcast

Diggin’ and Fetchin’ with TruffleRuby — Sometimes the largest journeys start with the smallest steps, like here where a small refactor ballooned into finding a bug in TruffleRuby along with a potential contribution to the language.

Julie Antunovic (Shopify)

🛠 Code & Tools

oktest: A New Testing Library for Ruby — oktest is a new spec-like testing library that has an impressive amount of features with a claim of “good performance”. I love the clean style of the assertions.

kwatch

Modularity: Traits and Partial Classes for Ruby — Enhances Module so it can be used to define traits and partial classes which can make your meta-programming experiences better.

makandra

Crunchy Bridge: Fully Managed Cloud Postgres

Crunchy Bridge sponsor

wipe_out: Library for Resetting Data in Rails ActiveRecord Models — wipe_out allows you to create a “plan” that will remove, reset, or generate and overwrite data for a given schema. The first use case I thought of was sanitizing production data for a test environment.

Global App Testing

Standard 1.2: A Ruby Style Guide, Linter and Formatter — As StandardJS is to JavaScript, Standard is to Ruby.

test double

Futurism 1.0: Lazy-Load Rails Partials via CableReady
StimulusReflex

SearchKick 4.6: Intelligent Search Made Easy with Elasticsearch
Andrew Kane

Restforce 5.1: A Ruby Client for the Salesforce REST API
Restforce

💡 Tip of the Week



Extend

Last week, we learned something important about singleton classes: class methods are instance methods on a class' singleton class. Let's take a step back though - how is this relevant to extend?

We already know that include inserts a module into the class' ancestors chain right after the class that includes it and prepend inserts it right before. Well, extend also inserts a module into an ancestors chain, but it does this on the ancestors chain of the singleton class of a class (not the class itself):

module ExampleModule ; end

class ExampleClass
  extend ExampleModule
end

ExampleClass.ancestors
=> [ExampleClass, Object, Kernel, BasicObject]

ExampleClass.singleton_class.ancestors
=> [#<Class:ExampleClass>, ExampleModule, #<Class:Object>,
#<Class:BasicObject>, Class, Module, Object, Kernel, BasicObject]

The #<Class:ExampleClass> syntax means it's the singleton class of ExampleClass. We can see thatExampleModule is inserted into ExampleClass's singleton class' ancestors chain.

Let's combine this with what we've learned about singleton classes - instance methods on a class' singleton class are class methods on that class. So say we had an instance method defined on ExampleModule:

module ExampleModule
  def example_module_instance_method
    "This is an instance method defined on ExampleModule"
  end
end

If we extend ExampleModule it will become a class method on ExampleClass:

class ExampleClass
  extend ExampleModule
end

ExampleClass.example_module_instance_method
=> "This is an instance method defined on ExampleModule"

If we had instead used include on the same ExampleModule, this would remain an instance method:

class ExampleClass
  include ExampleModule
end

ExampleClass.new.example_module_instance_method
=> "This is an instance method defined on ExampleModule"

Nice! We've now learned three ways to use code from a module in a class:

  • include inserts a module into the class' ancestors chain right after the class.
  • prepend inserts a module into the class' ancestors chain right before the class.
  • extend inserts a module into the class' singleton class' ancestors chain right after the class, meaning essentially all of the module's instance methods can be accessed as if class methods on the class which extends it.

This week’s tip was written by Jemma Issroff.

🎨 A Fun One..

PNGlitch: A Ruby Library to Glitch PNG Images — This isn’t just a visual effect applied to your image - the data is actually ‘glitched’ but the checksums are updated to make them still render. This means the result is rather.. dramatic.

ucnv