amiel/bitmasker — pull request #1 by amiel (2012-12-21 18:35:27+00:00)
Title: Bitwise logic ActiveRecord scopes

It still needs some testing in the wild, and probably some more scope methods (like with_any_, with_exact_, etc).

Documentation

Given:

class User < ActiveRecord::Base
has_bitmask_attributes :notifications do |config|
config.attribute :send_weekly_newsletter, 0b0001
config.attribute :send_monthly_newsletter, 0b0010, true
end
end
This patch allows you to:

User.with_notifications(:send_weekly_newsletter)
# => scope for all users where send_weekly_newsletter is true, regardless of the other attributes.

User.with_notifications([:send_weekly_newsletter, :send_monthly_newsletter])
# => scope for all users where send_weekly_newsletter is true, AND send_monthly_newsletter is true

User.without_notifications(:send_weekly_newsletter)
# => scope for all users where send_weekly_newsletter is false, regardless of the other attributes.

User.without_notifications([:send_weekly_newsletter, :send_monthly_newsletter])
# => scope for all users where send_weekly_newsletter is false, AND send_monthly_newsletter is false
I'm also looking for feedback.