Weeknotes 47
22nd May, 2022
“Arbitrary commands”
-
Simon B. Støvring noticed that his Runestone repo was trending on GitHub for the C language, but the project itself is Swift. This is caused by vendoreding dependencies included via submodules. The solution, as indicated by Sindre Sorhus, is to set the dependencies as vendored using the
.gitattributes
file that Linquist uses to determine the language of a repo. -
“ComparisonValidator example code does not work” – I was confused by this behaviour recently.
class Person < ActiveRecord::Base validates_comparison_of :birth_date, less_than_or_equal_to: -> { Date.today } end
Which will result in a
ActiveRecord::RecordInvalid
with this message:Birth date wrong number of arguments (given 1, expected 0)
You must remember to supply an argument for the record instance when using a lambda like
->(_person) { Date.today }
, but soon this won’t be necessary since @fatkodima made this change: Make validators accept lambdas without record argument. -
Gary Bernhardt writes about a neat way of tracking TODOs in a project (via Steve Klabnik) – have them fail the linter. Ironic that I post this after my appeal to not appease the linter last week.
Shane Becker follows up with @searls'
todo_or_die
gem for Ruby which has a similar vibe but different approach. -
“Provide pattern matching for ActiveModel #45035”. Even though Ruby’s pattern matching seems a bit awkward to me (to be fair, I haven’t had much of an opportunity to use it yet due to my project’s Ruby version) this is cool.
case Current.user in { superuser: true } "Thanks for logging in. You are a superuser." in { admin: true, name: } "Thanks for logging in, admin #{name}!" in { name: } "Welcome, #{name}!" end
-
I was updating some documentation for Rake tasks this week. You use the
desc
method to document tasks and they can be listed with-T
(--tasks
) and-D
(--describe
).-T
will show an abbreviated description - just the first line of the description, whilst-D
will show the full, multi-line, description. -
Checkout just how cool the Oban Pro dashboard is 😎 This is what is possible using LiveView, PubSub etc with Elixir and Phoenix.
-
TIL about the slightly lesser used ERB delimiters. I never remember that
<%-
will trim the preceding indentation, and-%>
trims the following line break. I’ve only been using ERB for multiple years, so give me a break. -
Keep your team up to date on production data changes is a really nice idea – hack IRB in production to output all commands to Slack so there’s visibility of what is being done.
This has been a problem everywhere I have worked to some degree. Rigorous testing, PR reviews, and manual testing, but then allowing arbitrary commands to be run in production!