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

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

Instance Method Summary collapse

Methods included from Roles::Mongoid::Strategy::Single

#add_roles, #remove_roles, #roles_list

Methods included from Roles::Mongoid::Strategy::Shared

#get_roles, #select_valid_roles, #set_role, #set_roles

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