martinrehfeld/role_model — pull request #25 by andrewhubbs (2013-02-04 19:12:50+00:00)
Title: Add `class.mask_values_for` function

Added a function that will return the valid values of `role_mask` for the given roles.

This function is very useful for making `SQL` queries based on role. For example, in your Rails model you may want to define a scope like so:

```ruby
class User < ActiveRecord::Base
roles :admin
scope :admin, where(roles_mask: self.mask_values_for(:admin))
end
```
or
```ruby
class RestaurantStaff < ActiveRecord::Base
roles :chef, :sous_chef, :bartender, :waiter
scope :chefs, where(roles_mask: self.mask_values_for(:chef, :sous_chef))
end
```

The primary down side to this function is that the return value will start to get unwieldy when you have > 10 roles. I expect this is uncommon for most uses though.