Skip to content →

Category: dev

Postgres Container Access with a SQL Client

 As you may have read I like to use Postgres’ official image in my multi-container Docker environment. Out of the box it needs little configuration. I typically access it through my Rails app using  rails db or  rails console . The other day, however, I needed to craft some SQL and those tools weren’t cutting it. I wanted to use my SQL client so I could work directly with the schema on something better than the command line. That required some tweaking to my DB container. By default the Postgres image uses Docker’s EXPOSE instruction to open port 5432 for other Docker containers. EXPOSE does not make the port…

Continue reading Postgres Container Access with a SQL Client

Leave a Comment

Please Stop Abusing NotImplementedError

The purpose of NotImplementedError is defined in the Ruby docs: NotImplementedError is raised when a feature is not implemented on the current platform. For example, methods depending on the fsync or fork system calls may raise this exception if the underlying operating system or Ruby runtime does not support them. So whenever I see code like this:

I cringe. Raising NotImplementedError simply to signal that a subclass didn’t abide by the contract of its superclass is an abuse of the error. The error is intended to be raised when a method cannot be implemented due to a limitation of the underlying…

Continue reading Please Stop Abusing NotImplementedError

2 Comments

ActiveRecord Coerces Values Set with #id= into Fixnum

I found a bug in my code today that stems from my not remembering that ActiveRecord::Base will try to coerce values set on its attributes into whatever type is defined in the DB. Specifically I got burned by #id= coercing a String into a Fixnum. Check this out:

Not only is the type of object changed by setting the attribute but the leading zero is lost. Luckily my specs caught this. I know, I know it’s a bad idea to set #id yourself. You should let ActiveRecord do that for you. In my case I was trying to cleverly avoid…

Continue reading ActiveRecord Coerces Values Set with #id= into Fixnum

Leave a Comment

Rails Production Eager Loading Ignored by Rake Tasks

I got bit by the Rails production environment today. Here’s the scenario: I have a set of classes that all mixin the same module.

Upon include the module “registers” the class with another class

Once registered subclasses of ApiCheck  can perform actions using the registry. Those actions are run via rake tasks. In development, when classes are autoloaded (i.e. only loaded when referenced), the rake tasks work fine. In production, however, the tasks fail because, in the context of a rake task,  ApiCheck.registry is empty. None of my classes were registered. This struck me as odd because in production Rails eager loads…

Continue reading Rails Production Eager Loading Ignored by Rake Tasks

Leave a Comment