I worked with Ian Lesperance and Paul Meskers this week preparing LicenseFinder for its 1.0.0 release. In addition to performing some much needed refactoring on the codebase, we also added the following new features:

Support for more license types (we now detect Apache2, BSD, New BSD, Simplified BSD, MIT, LGPL, ISC, Ruby, and GPLv2).

A simplified command-line interface (there’s now just a single command license_finder, though we still offer an equivalent rake task (rake license_finder) if you want to use it for a CI build)

A completely rewritten README with clear usage instructions

An cucumber integration test suite that outlines all of the license finder features

Continuous integration via travis-ci.org

While developing the integration test suite, we had the need to shell out and run bundle outside the context of the license finder bundle. It turns out that in order to do this, you have to wrap your system calls inside a block passed to Bundler.with_clean_env:

Bundler.with_clean_env do
`cd somewhere && bundle`
end

If you ever find yourself bootstrapping applications from a ruby script that you need to bundle, keep this little-documented bundler feature in mind.

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`.
end
self.inheritance_deserializer = ->(type_before_cast) do
# Map the type identifier back into the appropriate class.
# Defaults (approximately) to `type_before_cast.constantize`.
end
end

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 rake.

Helps

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.

Interestings

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 —
http://github.com/crafterm/comma

Interestings

http://avatars.io/

STI rake gotcha

StiBaseModel.some_scope

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.

Helps

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.

Help!

Interestings

Vim-Clutch

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.