Module: Gemboree::ActsAsActor::InstanceMethods

Defined in:
lib/gemboree/acts_as_actor.rb

Instance Method Summary collapse

Instance Method Details

#access_levelObject



16
17
18
# File 'lib/gemboree/acts_as_actor.rb', line 16

def access_level
  roles.first.nil? ? 0 : roles.order('access_level desc').first.access_level
end

#add_role(name) ⇒ Object



32
33
34
35
36
# File 'lib/gemboree/acts_as_actor.rb', line 32

def add_role(name)
  return false if has_role?(name)
  role = Role.find_by_name(name)
  role ? roles << role : false
end

#change_role(name) ⇒ Object



43
44
45
46
# File 'lib/gemboree/acts_as_actor.rb', line 43

def change_role(name)
  roles.clear
  add_role(name)
end

#has_access?(level) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/gemboree/acts_as_actor.rb', line 20

def has_access?(level)
  access_level >= level
end

#has_role?(name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/gemboree/acts_as_actor.rb', line 28

def has_role?(name)
  roles.find_by_name(name)
end

#has_role_access?(name) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/gemboree/acts_as_actor.rb', line 24

def has_role_access?(name)
  has_access?(Role.find_by_name(name).access_level)
end

#remove_role(name) ⇒ Object



38
39
40
41
# File 'lib/gemboree/acts_as_actor.rb', line 38

def remove_role(name)
  role = has_role?(name)
  role ? UserRole.where(user_id: id, role_id: role.id).first.delete : false
end

#role_nameObject



12
13
14
# File 'lib/gemboree/acts_as_actor.rb', line 12

def role_name
  roles.order('access_level desc').first.try(:name)
end