I’ve just released a Rails plugin that simplifies dealing with boolean flags in ActiveRecord. It gives you a load of easy-to-read dynamic attribute-based finders and setter methods without you having to write a line of code. It’s perfect for eliminating the tedium that arises from defining things like this over and over again:
class Order < ActiveRecord::Base
def self.paid
find_all_by_paid(true)
end
def self.unpaid
find_all_by_paid(false)
end
def mark_as_paid
update_attribute(:paid, true)
# related tasks
end
def mark_as_unpaid
update_attribute(:paid, false)
# related tasks
end
end
There’s more information on the Flagger project page. Any feedback – comments, bugs, testing with obscure DBs – is very welcome.