Having just come off a project, Ian Lesperance and I spent the week working on some open source initiatives. We also spent the week showing new pivot David Edwards the ropes.
We started the week with a feature request to rails for customized STI (Single Table Inheritance) type serialization. On the project we just finished, we needed to model a legacy database that serialized integers instead of class names for the STI type, and unfortunately we found that Rails had no real API for overriding the type serialization, so we added the following:
class Foo < ActiveRecord::Base
self.inheritance_serializer = ->(klass) do
# Map the class to the appropriate type identifier.
# Defaults to `klass.name`.
self.inheritance_deserializer = ->(type_before_cast) do
# Map the type identifier back into the appropriate class.
# Defaults (approximately) to `type_before_cast.constantize`.
Ian also contributed a bug fix to ActiveRecord, fixing the
pluck method when the column name plucked is a reserved word.
We then continued with a pull request to rubygems.org for adding license information to gem version pages and version api requests. In our line of work, we have to keep a vigilant eye on the software licenses of our dependencies; adding more exposure of licenses can’t hurt.
This segued nicely into some much needed work on
LicenseFinder, an open source project Pivotal Labs created and maintains to automate the process of keeping track of your project’s license dependencies. We’ve added detection for two more license types (”LGPL” and “ISC”), added proper integration tests to the project, put the project on Travis-CI, and refactored some of the code along the way. In the future, we’d like to create a proper command line interface for
license_finder so that you can use it without
Should attributes changed during after_save/after_create callbacks be marked as dirty?
We were surprised to learn that attributes changed in after_save/after_create callbacks were not marked as dirty.
Weigh in here.
ActiveRecord#Migration.add_column with default
In Rails 3.0, does not use the single line Postrges
ALTER TABLE foo ADD COLUMN bar TEXT DEFAULT wibble, which will back-populate
NULL columns. If you set null: false, it will use a non-optimal approach to back-populate NULL rows.
Comma — easy CSV generation
Comma is a CSV generation extension for Ruby objects, that lets you define a CSV output format via a DSL —
Chrome on iOS
Available on iPad and iPhone.
Fireworks on Saturday!
Pyromaniacs get ready: fireworks Saturday through Wednesday in NYC.
Interested hosted avatar service for getting user avatars from Twitter, Facebook, Intragram, Gravator or Custom.
STI rake gotcha
- works as expected in rails console (dev)
- works as expected in tests
- exhibits unexpected behavior in a rake task (in development mode)
It’s caused by an autoloading gotcha in dev mode with STI models, which oddly isn’t reproducible in rails console in dev mode (on Rails 3.2.5). The children of the STI model aren’t autoloaded in the rake task in dev mode, so the “type = ?” clause in the queries don’t include the subclasses of the STI base.
Free Boingo wifi in the subway
Free wifi all over the city from Boingo, including subway stations.
custom time components in rails 3.0.*
Overridden method from AR::Base so that we can use parameterized date/times, but not the typical fields used by Rails date/time pickers.
However, in the error state, the original value is lost. Typically Rails uses <attr>_before_type_cast to get the error data, however, it doesn’t work in this case.
I’m sure we are all tired of pressing ‘i’ and escape to enter and exit insert mode in vim ; vim-clutch lets us pretend we are using a sewing machine and use our feet. Pressing the clutch sends an ‘i’ signal, and releasing it sends an escape.
Threadsafe is on by default in the next Rails