Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am nickpellant on github.
  • I am nickpellant (https://keybase.io/nickpellant) on keybase.
  • I have a public key whose fingerprint is 310E 9516 1D11 17FD 3EA7 834C 90FF EF4D E089 689C

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am nickpellant on github.
* I am nickpellant (https://keybase.io/nickpellant) on keybase.
* I have a public key whose fingerprint is 4621 B269 FB02 D222 6F7E 556E 9A07 9E85 A280 0922
To claim this, I am signing this object:
@nickpellant
nickpellant / gist:2652244
Created May 10, 2012 10:00
Roles in Rails
class User < ActiveRecord::Base
ROLES = [:admin, :basic]
scope :with_role, -> role { where("roles_mask & #{2**User::ROLES.index(role)} > 0") }
# Checks whether the roles passed in list are set for the instance.
# @param [Array<Symbol>] roles The list of role symbols to check.
def role?(*roles)
self.roles.any? { |role| roles.include? role }