Issue #6 - 15-21 August 2022

The one with deep conversations

Hello,

I’m Lucian (find me on Twitter @lucianghinda), and I am the curator of this newsletter. Thank you for subscribing to this newsletter.

This edition was created with support from @adrianthedev from Avo for Ruby on Rails (a friendly full-featured Rails admin panel) and from @jcsrb, who sent me recommendations to include in the newsletter.

Andy Leverenz shared a nice and simple piece of wisdom:

Simple scales, fancy fails.

Cezar Halmagean shared some topics that a junior developer should focus on along learning the language or framework:

Every junior Rails developer should learn more about: 1. Testing 2. N+1 queries 3. Back-end performance optimizations 4. Page speed 5. Business goals What else?

Among other points that people shared in the conversation were:

  • “Radical candor, and graciously accepting feedback. That goes for seniors too!” (source) by inkyvoxel

  • “Rubocop, Hotwire, Refactoring, design patterns and how to avoid shitty jobs” (source) by Benjamín Silva H.

  • “Accessibility” (source) by Konnor Rogers

  • “controllers, views, and forms do not need to reflect a single underlying model. - you could have two different controllers changing the same model based on usage - one controller / view form may update multiple models” (source) by Rose W

And there are many more concrete examples of things to learn for juniors in that thread.

Nick Schwaderer shared an example about undefining all instance variables but keeping a secret reference:

Jim Weirich's BlankSlate class (which predates BasicObject!) does this in a really cool way by undefining all instance methods (but for two) and keeping a secret reference to all of them where they can be redefined or revealed.

Here is what that class looks like from the example on Github:

Sample source code for BlankState definition

Joel Drapper asked about how to simply serve static files on Ruby:

What’s a simple way to serve static files locally in Ruby? I basically want to mirror what GitHub pages will do with the generated files.

And received a lot of good suggestions (not only from Ruby):

# == Utilities to replace common UNIX commands in Makefiles etc # # == SYNOPSIS # # ruby -run -e cp -- [OPTION] SOURCE DEST # ruby -run -e ln -- [OPTION] TARGET LINK_NAME # ruby -run -e mv -- [OPTION] SOURCE DEST # ruby -run -e rm -- [OPTION] FILE # ruby -run -e mkdir -- [OPTION] DIRS # ruby -run -e rmdir -- [OPTION] DIRS # ruby -run -e install -- [OPTION] SOURCE DEST # ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE # ruby -run -e touch -- [OPTION] FILE # ruby -run -e wait_writable -- [OPTION] FILE # ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION] # ruby -run -e httpd -- [OPTION] [DocumentRoot] # ruby -run -e colorize -- [FILE] # ruby -run -e help [COMMAND]

Ruby Gems Status shared that they started to require MFA for the popular gems:

Two months ago, we announced a policy to increase multi-factor auth adoption as a step to better secure RubyGems. Starting today, maintainers of popular gems will be required to enable MFA

Joe Masilotti asked about how to send a notification when subscription status changes:

Can anyone experienced with the Pay gem help me? I'm trying to send notifications when a subscription status changes. This feels ugly but I haven't found a better solution. 1. Is there a better way? 2. If not, did I miss any cases? CC @excid3 @collin_jilbert

He also shared a piece of code about what he tries to do and received a nice reply from Vladimir Dementyev about how to use pattern matching (see full gist here):

Paolo Perrotta asked for resources to catch up with Ruby:

Ruby folks: I'm out of the loop, and looking to catch up. Is there any go-to place these days where the Ruby community congregates? Is everybody just using Twitter, or are there subreddits / Discord servers / whathaveyou to keep up with the community and the language? Thank you!

There are so many exciting replies that I don’t know what to pick. Here is one that I did not know so far https://discord.gg/stimulus-reflex Discord channel.

Joe Masilotti asked for advice on how abstract styles when working on Tailwind. It seems the main recommendation is to not use apply and use components.

Rails + Tailwind CSS/UI folks: how do you abstract your styles? @apply for concrete elements like buttons? A verbose Tailwind config? Lots and lots of partials? I'm struggling to consolidate some styles on RailsDevs and would love to hear how you do it!

Jared White shared that he is working on a new project. More details are on The Spicy Web Discord server link to join

I’m putting my money where my mouth is (so to speak). I’m building a tool to convert Tailwind utility class HTML soup to 100% vanilla HTML + CSS with design token variables. Output looks virtually identical. Copypasta from your favorite TW UI library, click a button, and boom!

Emmanuel Hayford shared about Enumerable having first but not last:

Just learned there's Enumerable#first but no Enumerable#last, so while you can do Hash#first, you can't do Hash#last. Dug a bit. The reason might be for efficiency and how elements are traversed. This deserves a blog post with more details.

Jean Boussier asked about GitHub Actions to trigger build when you push to a branch without opening a PR, but not to build twice:

Did someone ever figure out how to get GitHub Actions to trigger build when you push to a branch without opening a PR, but not to build twice when you do? I think I went over their documentation a dozen time but can't wrap my head about how it's supposed to work.

There were suggested a couple of solutions:

Colby Swandale shared that he is working on a list of Ruby engines.

Last year I put together a single page app that listed all the different Ruby engines. You could click to see the project's page, links to socials, github etc. I forgot about this work since last year, and i'm wondering if people would be interested in this being published?

Alef Oliveira shared a piece of code adding methods on top of the Hash:

I was doing some work here and I saw a need for the hash data type in ruby, so I added a method on top of the Hash class, it was super cool to understand this class subscript. #ruby #rails #hash #class

Joel Drapper shared some code samples from gems he is maintaining:

I tweet a lot about Phlex but did you know I maintain a few other gems? Here’s one called ActionState. It’s a little DSL for defining Rails scopes and predicates at the same time.

Emmanuel Hayford shared a sample of using the Ruby … syntax:

One of my favourite features of modern Ruby is the `...` syntax for delegation or argument forwarding. It's elegant and saves some keystrokes.

Benito Serna shared a sample code about using self for chaining methods:

#ruby Tip If want to run several methods from an object in a row you can return self and "chain" them. Sometimes it makes it look elegant (I think 😀)

Hiroshi Shibata shared they merged syntax_suggets is now part of Ruby standard library:

`syntax_suggest` is a part of the Ruby standard libraries now.

Read more about the discussion about merging this to Ruby here and link to the Github PR here.

Facundo Espinosa asked about how to build a design library:

I’d love to know from those who built a design library with ViewComponents, do you have some kind of organization for them? For example, I’m using ViewComponents and I store them in a folder called design, so we have Design::ButtonComponent and so on.

Some interesting suggestions:

We have a separate gem and yes there is a prefix with the design system name (oh so fancy it has a name) - Josef Strzibny

I’m liking the idea of putting them all in a module, e.g. Components::Button because then you can use relative references for other component constants. - Joel Drapper

We use UI module for generic things UI::Modal UI::Tab and then app specific modules for things like Tasks::ListItem - Matt Swanson

Joel Drapper shared a new update for the performance improvements in Phlex:

Almost 5× ActionView partials now

Joe Masilotti shared a sample code with View Components + class_names + polymorphic slots:

View Components + class_names + polymorphic slots

Joël Quenneville shared how cycle from Ruby works similarly with Haskell cycle:

TIL that #Ruby's `cycle` (without the block) acts similarly to #Haskell's cycle to form an infinite cycled list: Haskell take 10 $ cycle [1, 2, 3] => [1, 2, 3, 1, 2, 3, 1, 2, 3, 1] Ruby [1, 2, 3].cycle.take(10) => [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]

Colleen Schnettler shared that there might be a market for Rails themes:

I feel like there is *such* a market for Rails friendly Tailwind themes. There ya go. Third business idea of the week. Follow along for more world domination.

On the same topic Joel Drapper shared:

I wonder if there would be a market for “Webflow” for components. A GUI design interface that produces Phlex component files.

Based on the replies from both these conversations there seems to be a desire for more UI libraries/projects in the Ruby/Rails world.

Adrian Marin from www.avo.cool asked a question about pains when creating UIs in Rails.

Quick question: What's the one thing you hate the most about creating UIs for your Rails apps? (Let it rip. Don't hold back!)

Among the mentioned pain points:

  • Missing UI libraries compatible with Rails

  • Finding talented UI developers

  • Working with ERB and partials

Thiago Massa created a poll about which debugger you use the most often in Ruby:

Which debugger do you use the most often in Ruby? (RTs really welcome, my Twitter network is kind of limited and this would help me to prepare my new talk. I will mention you there ❤️) and results: Pry 55.2%, Ruby Debug 11.7%, Byebug 23.7%, Other: 9.4%

It is worth reading the discussion this poll generated and also the following discussions from what Thiago shared after the poll closed: one discussion here about preference for debugging in REPL and one here where he asked how devs are using debuggers.

Kevin Kuchta shared a funny take about the Ruby community:

You know what the problem with the ruby community is? They're too damn reasonable. I just want to monkey patch the array literal constructor and all I find are articles on how to *avoid* doing that. Just help me accomplish my bullshit, damnit!

Read the replies as there are interesting code examples offered there

If you read so far and you like the content, maybe you take into consideration sharing this and subscribe:

Related (but not Ruby specific)

Adrien Poly asked about recommendations on how to create a memo about what happened during the week:

Do you create a weekly memo for your work to share with your team? With like a summary of your PR, commits & achievements of the week. If yes what tools do you use for that ? At the end of the week I usually don’t remember half of what I did looking for tools to help.

He received two interesting replies:

Greg Molnar shared a good picture of the advantages of automated tests:

an image describing advantages of automated tests: peace of mind and easy debugging over disadvantages: hard to debug, regression is hard and hard to reproduce bugs

Daniel Vassallo shared a view about skipping unit tests that triggered a lot of discussions about coding without tests:

Here is one exciting reply among many others from Cody Norman:

@bphogan It can feel like you're moving faster skipping unit tests but when you inevitably introduce a regression, your valuable time for development is shifted to finding the problem and what caused it. That's a great way to lose momentum and sour on the project

Postmodern shared an excellent way to think about TDD/BDD that could help define when to stop:

A subtle/implicit purpose of TDD/BDD/test-coverage-driven-development is that it gives you a fuzzy stopping point. Do all of the tests pass and code coverage is >90%, then you are done [for now] and can move onto the next task.

Edward J. Stembler shared a little code in Crystal about a Blacklist Handler that I think with just some small changes could be copied to Ruby:

Yehonathan Sharvit asked a question about accepting extra fields in request payload that triggered a wide range of replies:

When we design a REST API should we accept extra fields in the request payload? In my book, influenced by @richhickey, I claim that yes, quoting Jon Postel' robustness principle: "Be conservative in what you send, be liberal in what you accept." Do you agree?

Brandon Weaver shared why he thinks juniors are a critical path to healthy growth in engineering teams. Read the entire thread it is super good.

Juniors are absolutely critical to the healthy growth of engineering teams, and overall companies, yet there seems to be such a disconnect in hiring practices and how this has played out in some major companies. Why is that? Well, a few reasons, but let's start with value.

Articles and Videos

Communities

Stephan Hagemann shared a new Slack channel “ where folks are chatting about Ruby and Rails Modularity”. Join here

Hanami Mastery shared there is a Twitter community for Dry-Rb. You can join it here

Courses

Jason Swett launched his The Complete Guide to Rails Testing - Code with Jason that can come together with Video Course: Ruby DSLs Demystified.

Ruby Companion shared a new course they added to the learning topics: Rails API. See the image that explains the course topics here.

Jason Charnes shared that he is working on a new course named “Next Level Active Record”. Subscribe to get updates here.

Something to read

Newsletters

Articles

Gomez shared an article written by them on the PlanetScale blog about How to disable Sidekiq jobs in production

Felipe Vogel shared 2 reading recommendations:

Charles Lambdin shared a new article they wrote about Estimating Cost of Delay

Samuel Williams shared a great discussion on the Falcon Github that helps understand more about how Rails/Active Record works and their limitations Read the discussion here.

Something to watch or listen

Videos

Go Rails shared a new episode where Collin is doing an SQL Introduction with PostgreSQL: See it here → SQL Introduction with PostgreSQL

Timnan shared an episode about creating a chat in Rails 7: See it here → Episode 23 Turbo Powered Chat Application in Rails 7.

Cecil L. Phillip shared they released a new episode of DevChats where Chris Oliver was invited. See it here → Dev Chats - Extending Rails with Engines

Ian shared a link to a video about building your own spec: See it here → RSpec Tutorial: Build Your Own RSpec

Ernesto shared that he was a quest on the @duckiedevshow. See the episode here → Code Quality, RubyCritic & Skunk with special guest Ernesto

Drifting Ruby shared a new video walkthrough for This Week in Rails. See it here → This Week in Rails Aug 19th, 2022

Avo shared a video walkthrough of features they released in their latest release. See it here → Customizable controls on the show page, scoped search for has_many and more

Audio

Felipe Vogel shared an old podcast episode of Ruby Rogues where Sandi Metz talks about the four rules for developers: Listen to it here → Practical Object-Oriented Design in Ruby with Sandi Metz

Stephan Hagemann shared a recording from the Twitter Space about “discussion about packwerk, stimpack, code ownership, what apps we should use these tools on, and how teams can get started”. Listen to it here → Ruby@Scale. Packwerk. Gradual Modularization. How are things going?

Joe Masilotti shared that he is starting to do monthly office hours. Listen here to the recording of the first session: Monthly office hours - bring your questions!

Remote Ruby shared they published a new episode where the quest was Sebastian Wilgosz. Listen to it here → Hanami Mastery with Sebastian Wilgosz

Ruby for All released a new episode about getting unblocked. Listen to it here → Getting Unblocked

New libraries and updates

Avo released a new version, 2.13.10. Read the changelog here.

Josef Strzibny shared a gem that can auto-generate models, views, controllers and routes based on Database structure: brick

Stephan Hagemann shared Gusto’s attempt at collecting a set of tools to help scale Ruby (and Rails) engineering organizations. You can find them all in Github at rubyatscale. Among the gems here (there are many):

  • stimpack establishes and implements a set of conventions for splitting up large monoliths built on top of packwerk. 

  • CodeOwnership  helps engineering teams declare ownership of code.

  • Packwerk for Visual Studio Code

  • danger-packwerk integrates packwerk with danger to provide inline comments in PRs related to boundaries in a Rails application.

Nils shared about a new gem called “acts_as_nosql” - a gem to manage JSON fields as proper database fields:

lass User < ApplicationRecord acts_as_nosql field_name: :data # You can define multiple attributes at once with the same type nosql_attrs :first_name, :last_name, type: :String # You can set the default value nosql_attr :age, type: :Integer, default: 0 # You can also pass a :path attribute # This is used to decide how to write the attribute as a nested object # In this example, `google_oauth_token` will be written in the JSON object as: # `"oauth" => { "google_token" => __VALUE__ }` nosql_attr :google_oauth_token, type: :String, path: [:oauth, :google_token] # You can run standard ActiveRecord validations on these fields validates :first_name, :last_name, presence: true end user=User.new # You can use attributes as standard user.first_name = 'John' user.last_name 'Doe' # This picks the default value user.age # => 0 # This is stored as a nested object user.google_oauth_token = 'xxxxxxx' user.save! # All attributes are stored in the `data` column user.data # => { "first_name" => "John", "last_name" => "Doe", "age" => 0, "oauth" => { "google_token" => "xxxxxxx" }} # You can also run basic queries: User.where(first_name: 'John').to_sql # => SELECT "users".* FROM "users" WHERE "users"."data"->>"first_name" = 'John'

I just released https://t.co/qRyNEGFErC which allows you to host a rack compatible application within async-http without falcon. It implements rack2 and rack3 adapters. Applications could target `protocol-http` interfaces and be hosted within Rack compatible servers.

Hanami shared they release version 2.0.0.beta2: Announcing Hanami v2.0.0.beta2:

This release includes slice and action generators, middleware inspection, and conditional slice loading.

Chris Oliver shared they will be the new maintainer for sequenced gem sequenced - Generate scoped sequential IDs for ActiveRecord models:

The focus was to bring the awaits feature to the heart of the gem and ensure it was robust.

I can honestly say that asynchronous but blocking jobs have completely changed the way I think about and architect my apps. I lean on background jobs immensely, and I orchestrate quite complex workflows with ease. But the throughput remains high. It is truly awesome.

Gomez shared the release of a new gem FastPage. You should read the article about this gem: Introducing FastPage: Faster offset pagination for Rails apps

Jeremy Evans shared the release o sequel_pg version 1.16.0. See changelog here

Jean Boussier shared that redis-rb 5.0.0 first beta is finally out. See the changelog here.

Joel Drapper shared a list of gems he is maintaining:

K0kubun shared a new beta release of Haml: Release 6.0.0.beta.1 · haml/haml

This was a long issue as there was a lot of great content that I discovered in Ruby community.

Please consider sharing this on social media or with your colleagues. I hope I added content for a wide range of developers (beginners to experts)

Reply

or to participate.