Skip to content

Commit

Permalink
Merge pull request #9 from ryanmccarthypdx/cancan3
Browse files Browse the repository at this point in the history
edit user model
  • Loading branch information
jasandine committed May 2, 2015
2 parents a5bf91b + 4ab2229 commit 8694f28
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ class User < ActiveRecord::Base

Roles = [ :admin, :default ]

def is?( requested_role.to_s )
self.role == requested_role.to_s
def roles=(roles)
self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum
end

def roles
ROLES.reject { |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? }
end

def role?(role)
roles.include? role.to_s
end
end

0 comments on commit 8694f28

Please sign in to comment.