amiel/has_bitmask_attributes — pull request #2 by amiel (2012-12-18 01:19:42+00:00)
Title: Bitwise logic scopes

An initial implementation of #1

It still needs some testing in the wild, and probably some more scope methods (like `without_scope`, `with_exact_scope`, etc).

### Documentation

Given:

```ruby
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:

```ruby
User.with_notifications(:send_weekly_newsletter)
# => scope for all users with send_weekly_newsletter set, regardless of the other attributes.

User.with_notifications([:send_weekly_newsletter, :send_monthly_newsletter])
# => scope for all users with send_weekly_newsletter set, OR send_monthly_newsletter set
```

I'm also looking for feedback.