-
After last week, we decided to decamp to my parents’ house for the foreseeable future.
The day after we made the decision, C came home from nursery with a cold and E caught it soon after. We waited for it to pass but, by Friday, our anxiety led to a last minute coronavirus test and a nervous two day wait for the result. Just as we were about to give up travelling that weekend, the text message arrived: a negative result.
Within seconds, E ordered our first (and perhaps only) Pret of 2020 while we loaded up the car. Complaining about the inexplicable popularity of cranberries in every festive sandwich, we drove north without stopping, listening to Adam Buxton interview Sir Paul McCartney along the way.
-
With my parents available to look after C, I spent the day I usually look after him alone constructing a climbing frame.
The instructions said it would take two people four hours to complete. It took me around seven hours to screw, bolt, drill and hammer together the finished product.
It’s no 1960s cocktail cabinet but it is the most complicated thing I have built.
-
During C’s giddy exploration of his new surroundings, he threw my parents’ 23 year old telephone base station on their kitchen tiles. It immediately stopped working, rendering all of their handsets useless.
Upon inspection, we realised the station had landed on its own cable, severing two of four wires within.
After speaking with my father-in-law, he lent me his soldering iron and some solder sleeves and I attempted to reattach each of the four wires.
I have never successfully repaired anything by soldering but this was my very first success!
-
I used Rake’s
multitask
for the first time:Same as a regular task, but the immediate prerequisites are done in parallel using Ruby threads.
desc 'Run all migrations in parallel' multitask migrate: %i[migrate_issues migrate_books migrate_magazines] desc 'Migrate issues' task migrate_issues: :environment do # ... end # ...
-
My adventures with Rails’ Active Storage continue and the use of direct routes stands out while reading the source code. This allows you to create powerful routing helpers that take arbitrary objects (rather than relying on overriding
ActiveRecord::Base#to_param
):get '/downloads/:signed_id/*filename' => 'downloads#show', as: :download_blob direct :download do |object, options| signed_id = object.some.custom.signed_id filename = object.another.custom.filename route_for(:download_blob, signed_id, filename, options) end # So now you can call.. download_path(object) download_url(object)
-
While I’ve since given up on Active Storage’s public access mode as it doesn’t let you set a
Content-Disposition
with S3, trying to make it work led me to discoverAws::S3::Object#public_url
doesn’t respect the AWS client’s:use_accelerate_endpoint
option to enable Amazon S3 Transfer Acceleration.You can work around this by instead setting a custom
:endpoint
in your client configuration:amazon: service: S3 endpoint: "https://s3-accelerate.amazonaws.com"
-
I also disappeared down a bit of a rabbit-hole trying to debug why an Active Storage Variant in my tests wasn’t being detected as
processed
.After much use of Pry, I discovered the bug was being caused by the fact Variant keys are generated by
ActiveSupport::MessageVerifier#generate
which usesMarshal.dump
to serialize a Variant’s transformations and, while my test variant seemed identical to the expected variant, there was a very subtle difference: the filename of the test variant was encoded with ASCII, not UTF-8:> Marshal.dump(variant1.variation.transformations) "\x04\b{\b:\vformatI\"\bpng\x06:\x06ET:\x12resize_to_fit[\a0i\x01\x80:\fconvertI\"\bjpg\x06;\x06T" > Marshal.dump(variant2.variation.transformations) "\x04\b{\b:\vformatI\"\bpng\x06:\x06EF:\x12resize_to_fit[\a0i\x01\x80:\fconvertI\"\bjpg\x06;\x06T"
The difference can be hard to spot: it’s the
\x06ET
afterpng
instead of\x06EF
.This stems from the encoding of
Rails.root
being ASCII (which is due to the underlying behaviour ofPathname
) andRack::Test::UploadedFile
using that filename to determine theoriginal_filename
.Passing an explicit
:original_filename
fixes this:Rack::Test::UploadedFile.new( Rails.root.join('spec/fixtures/image.png'), original_filename: 'image.png' )
I warned you it was a rabbit-hole.
Weeknotes 59 and 60
By Paul Mucur,
on