ruby

bash
#!/usr/bin/env bash
set -euo pipefail

bundle exec bundler-audit check --update
npm audit --audit-level=high
pip-audit --strict

Dependency vulnerability scanning for Ruby and Node projects

dependency-scanning supply-chain ruby
by Kai Nakamura 1 tab
ruby
class Timer
  def self.measure
    start_time = Time.now
    yield if block_given?
    end_time = Time.now
    end_time - start_time

Blocks, Procs, and Lambdas for functional programming

ruby blocks procs
by Sarah Mitchell 3 tabs
ruby
# Gemfile
gem 'dry-types'
gem 'dry-struct'

require 'dry-types'
require 'dry-struct'

Dry-rb gems for functional programming patterns

ruby dry-rb functional-programming
by Sarah Mitchell 2 tabs
ruby
# Generate engine
# rails plugin new billing --mountable

# lib/billing/engine.rb
module Billing
  class Engine < ::Rails::Engine

Rails engines for modular applications

ruby rails engines
by Sarah Mitchell 2 tabs
ruby
# app/policies/post_policy.rb
class PostPolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      if user.admin?
        scope.all

Pundit for authorization and policy objects

ruby rails pundit
by Sarah Mitchell 2 tabs
ruby
class UserSearchQuery
  def initialize(relation = User.all)
    @relation = relation
  end

  def call(params)

Query objects for complex database queries

ruby rails query-objects
by Sarah Mitchell 2 tabs
ruby
# Gemfile
gem 'draper'

# app/decorators/user_decorator.rb
class UserDecorator < Draper::Decorator
  delegate_all

Decorator pattern with Draper for view logic

ruby rails draper
by Sarah Mitchell 2 tabs
ruby
# Basic Ractor usage
ractor = Ractor.new do
  # This runs in parallel, isolated from main thread
  result = heavy_computation
  result
end

Concurrent Ruby with Ractors and Async

ruby concurrency parallelism
by Sarah Mitchell 2 tabs
ruby
# Gemfile
gem 'graphql'

# Installation
# rails generate graphql:install

GraphQL APIs with graphql-ruby gem

ruby rails graphql
by Sarah Mitchell 3 tabs
ruby
# Gemfile
group :development do
  gem 'rack-mini-profiler'
  gem 'memory_profiler'
  gem 'stackprof'  # For flamegraphs
  gem 'bullet'     # N+1 detection

Performance profiling with rack-mini-profiler and tools

ruby rails performance
by Sarah Mitchell 2 tabs
ruby
class UserNotificationJob < ApplicationJob
  queue_as :default

  # Retry up to 5 times with exponential backoff
  retry_on StandardError, wait: :exponentially_longer, attempts: 5

Background jobs with Sidekiq and ActiveJob

ruby rails sidekiq
by Sarah Mitchell 3 tabs
ruby
require 'rails_helper'

RSpec.describe User, type: :model do
  subject(:user) { build(:user) }

  describe 'validations' do

Advanced RSpec testing with shared examples

ruby rspec testing
by Sarah Mitchell 3 tabs