Sha256: e3b2de7634e1d708780375f05dc1b50ff257a71c46d4dd934e974c6ec3b85271
Contents?: true
Size: 1016 Bytes
Versions: 2
Compression:
Stored size: 1016 Bytes
Contents
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :roles # attr_accessible :title, :body ROLES = %w(admin role-1 role-2 role-3) def self.create_oam_user(attributes) user = User.new user.email = attributes[:email] user.roles = attributes[:roles] if attributes[:roles] user.save validate:false end def roles=(roles) self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum end def roles ROLES.reject do |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? end end def update_roles(roles) self.roles = roles self.save validate:false end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
devise_oam-0.0.2 | test/dummy/app/models/user.rb |
devise_oam-0.0.1 | test/dummy/app/models/user.rb |