Module: RoleStrategy::Mongoid::AdminFlag::Implementation

Includes:
Mongoid::Roles::Strategy::Single
Defined in:
lib/roles_mongoid/strategy/single/admin_flag.rb

Instance Method Summary collapse

Instance Method Details

#get_roleObject



36
37
38
# File 'lib/roles_mongoid/strategy/single/admin_flag.rb', line 36

def get_role
  self.send(role_attribute) ? strategy_class.admin_role_key : strategy_class.default_role_key
end

#new_role(role) ⇒ Object



31
32
33
34
# File 'lib/roles_mongoid/strategy/single/admin_flag.rb', line 31

def new_role role
  role = role.kind_of?(Array) ? role.flatten.first : role
  role.admin?
end

#present_roles(*roles) ⇒ Object



40
41
42
43
# File 'lib/roles_mongoid/strategy/single/admin_flag.rb', line 40

def present_roles *roles
  roles = roles.flat_uniq
  roles.map{|role| role ? :admin : :guest}
end

#set_empty_roleObject



45
46
47
# File 'lib/roles_mongoid/strategy/single/admin_flag.rb', line 45

def set_empty_role
  self.send("#{role_attribute}=", false)
end