#​549 — April 22, 2021

Read on the Web

Ruby Weekly

Why Our Puma Workers Constantly Hung, and How We Fixed It by Discovering a Bug of Ruby 2.5.8 and 2.6.6 — This equally epically titled and epically long chase down the rabbit hole digs into the MRI crevices and tracks down a bug which was happily resolved in Ruby 2.7.2 and up. If you like chasing bugs from graphs down to the final resolution, this is for you. Issues around this area of Ruby have been raised before.

Yohei Yoshimuta

Bundler 2.2.3+ and the Deployment of Ruby Apps — If you’re seeing weird bundler platform errors on deployment nowadays (for example: “Your bundle only supports platforms "x86_64-darwin-20" but your local platform is x86_64-linux” then you probably need to read this article.

Prathamesh Sonpatki

On Heroku? Try Autoscaling the Rails Way — Avoid app slowdowns and slash your Heroku bill using the only autoscaler designed for Heroku and Rails. We automate both web and worker dynos (Sidekiq, Resque, DJ, and more). Try it for free in two clicks.

Rails Autoscale sponsor

Solidus v3.0 Released: A Rails-Based Ecommerce Platform — Solidus is a Spree fork originally created from a worry that Spree might not get updated anymore (although Spree is now fully alive). This 3.0 is a major level release due to a lot of removed deprecations (potential breakages for upgraders covered here).

Solidus Team

How to Build An App, Get Acquired by GitHub, Buy An App Back From GitHub and Then Sell It Again — If you’ve been in the Ruby world a long while, you might recall GitHub buying Speaker Deck from a company well known in the community. Here’s the whole story of how it went down.

John Nunemaker

Quick Bits

📘 Articles & Tutorials

A VCR + WebMock "Hello World" Tutorial — We all want our tests to be deterministic (no randomness and able to be repeated) and VCR and WebMock provide different ways to make HTTP requests to external systems predictable and repeatable.

Jason Swett

How to Protect Access to Rack Apps Mounted in Rails — Whether its your own creations or things like the Sidekiq or Flipper interfaces, mounting Rack apps into Rails apps is pretty easy and here’s a look at how to add some basic authentication.

Paweł Pacana

Bitfields, Explained Like I'm 5 — A basic introduction to why an array of true/false values could come in handy.

Krzysztof Zych

Free eBook: Efficient Search in Rails with Postgres — Speed up a search query from seconds to milliseconds and learn about exact matches, trigrams, ILIKE, and full-text search.

pganlayze sponsor

Ruby 3.1 to Allow Accumulation of Enumerable#tally Results — It’s still a way off, but Ruby 3.1 will introduce an optional hash argument for tally that will add counts to an existing set of results.

Ashik Salman

Listing the Contents of a Remote ZIP Archive, Without Downloading the Entire File — René compresses (HA!) lots of content about ZIP file structure and uncommon HTTP requests to fulfill this task.

René Hansen

Rails 7 Enables Scoping to Apply to All Queries — This fixes an inconsistency with the scoping method between class and object queries.

Apoorv Tiwari

The Future of Web Software Is HTML-over-WebSockets — The HTML-over-Websockets continues having a moment. This post goes through the history of how we got here and why the new approach takes the best of that history to make the future.

Matt E. Patterson

How and When to Use case Statements — If you’re using multi-branch if-else if statements in your code, case statements can make them much cleaner.

Shadi Rezek

▶  Reducing Friction at the Authorization Layer with John Nunemaker
Ruby Rogues Podcast podcast

Rails 7 Adds `invert_where` Method to ActiveRecord
Mayank Khanna

Jobs

Help Enzyme get Quality Medical Tech Into the Hands of Patients — As a Senior Full Stack Dev, help life science companies commercialize faster without compromising quality and patient care. Remote.
Enzyme

Ruby on Rails Engineers Wanted - Sr & Intermediate Level — We’re growing teams in Dublin/Riga/Toronto. Postgres, AWS, React, Redux. We’re one of the fastest growing SaaS companies globally.
Workday

Find Ruby Jobs with Hired — Take 5 minutes to build your free profile & start getting interviews for your next job. Companies on Hired are actively hiring right now.
Hired

🛠 Code and Tools

rgeo 2.3.0 Released: A Geospatial Data Library — Implements the industry standard ‘OGC Simple Features Specification’ for representing objects like points, lines and polygons along with a set of operations. The examples in the documentation will give you an idea as to its use.

Daniel Azuma and Tee Parham

FastRuby.io Guides You on How to Prepare Your Rails Application for an Upgrade

FastRuby.io sponsor

Reform 2.6.0: Form Objects Decoupled From Models — Gives you a form object with validations and nested setup of models. Framework-agnostic and doesn’t care about your database.

TRAILBLAZER

wt_activerecord_index_spy: Report Missing Database Indexes
WeTransfer

Disposable: Decorators on Top of Your ORM Layer
Nick Sutterer

OmniAuth Auth0 3.0: An OmniAuth Strategy to Login with Auth0
Auth0

DNSimple Ruby Client 6.0
DNSimple

acts_as_list 1.0.4: An ActiveRecord Plugin for Managing Lists
Brendon Muir

💡 Tip of the Week

Variable Pinning (Part 2 of 2)

In the Tip of the Week last week, we discussed how we could use variable pinning in pattern matching to compare a pattern to a local variable. Another use case for variable pinning in pattern matching is to compare a value within the same pattern.

Let's say we want to make sure that both elements in an array are the same, but we don't care exactly what they are. We can use variable pinning again here. Let's take a look:

case [1,1]
in [element,^element]
  "elements are the same: #{element}"
else
  "elements are different: #{element}"
end

=> elements are the same: 1

We assigned the first element to the variable element, and then used variable pinning (^element) to compare the second element to the first element.

We can also confirm that if the two elements in the array weren't the same, we'd fall into the else case, with element sitll set to be the first element of the array:

case [1,"different"]
in [element,^element]
  "elements are the same: #{element}"
else
  "elements are different: #{element}"
end

=> "elements are different: 1"

The Ruby docs give an interesting and practical use case for variable pinning. In the case from their example, we have a nested data structure where we have the school that jane is in, and the ids corresponding to each type of school. We want to find the id that matches her specific schoool type:

jane = {school: 'high', schools:[
         {id: 1, level: 'middle'},
         {id: 2, level: 'high'}]
       }

case jane
# select the last school, level should match
in school:, schools: [*, {id:, level: ^school}] 
  "matched. school: #{id}"
else
  "not matched"
end

#=> "matched. school: 2"

Neat! We assigned the variable school to the value with the key school, and then pinned school to ensure it matched the level. This led us to the id we sought for high school, 2. Variable pinning in pattern matching can be very helpful in these cases, as it allows us to match to values within the pattern itself.

This week’s tip was written by Jemma Issroff.