For reference only:
- rtx-cli
- Ruby 3.2.0
- Most dependencies installed via Homebrew
- macOS 14.2.1
- M3 Max chip
# app/models/user.rb | |
# | |
class User | |
after_create :foo | |
private | |
def foo | |
# ..something we don't do very often | |
end |
For some reason, I couldn't get the annotate gem to remove the file annotations | |
I used SublimeText w/ the following regex: | |
Find: `(?s)# == Schema Information\n(.*?)\n((# :nodoc:\n)?class)` | |
Replace: `class` (just adds back what I grabbed above) |
For reference only:
require 'base64' | |
file = File.open('path/to/file.ext', 'rb') # Read the image as binary | |
base64 = Base64.strict_encode64(file.read) # This gives you a string you can assign to a constant/variable | |
tmpfile = Tempfile.new(Base64.strict_decode64(base64)) # Decode and create a temporary file | |
Digest::MD5.file(tmpfile).base64digest # This is one way to create a checksum on the file | |
File.size(tmpfile) # You can also get a file size |
# frozen_string_literal: true | |
class MyStuff | |
OOPS = 'Oops' | |
def self.call | |
Rails.logger.warn { OOPS } | |
end | |
end |
# Lines marked with pry are just for testing in a rails console | |
require 'rspec/mocks' # pry | |
include RSpec::Mocks::ExampleMethods # pry | |
# This bypasses the warning that the method isn't called inside of a test | |
RSpec::Mocks.with_temporary_scope do # pry | |
stub_const( | |
'MyClass', | |
instance_double( |
# An example of class/instance methods w/ modules | |
module Foo | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
def foo | |
puts 'Bar.new.foo prints this' | |
end |
# these are examples; maybe not the right flags | |
gem install ffi -v '1.12.2' -- -- with-cflags="-Wno-error=implicit-function-declaration" | |
bundle config build.ffi --with-cflags=\"-Wno-error=implicit-function-declaration\" |
This is a strategy I use to find unused code in ruby projects. These instructions are for macOS, but you only need access to the tools for this to work.
/usr/local/bin/ctags . $(bundle list --paths)
to add all of my library methods for the project. This has some other benefits, like allowing code-jumping in vim
Bonus: You can set this command up as a git hook to run every time you make changes to your code locally. I have an example of this here
tags
file in your repository root to make sure it's populated with data correctly (`cat tags | w--- | |
name: Run Integration Tests | |
on: [workflow_dispatch] | |
# .github/workflows/integration.yml | |
# | |
# You manually trigger this from your Github actions. Maybe after merging to main, and triggering | |
# a deploy out to your pre-production environment | |
# |