Module: Roleable

Extended by:
ActiveSupport::Concern
Included in:
User
Defined in:
app/models/roleable.rb

Instance Method Summary collapse

Instance Method Details

#hasnt_role!(role) ⇒ Object Also known as: remove_role, delete_role, destroy_role



32
33
34
35
36
37
38
39
40
# File 'app/models/roleable.rb', line 32

def hasnt_role!(role)

  self.send(:"roles=", []) if !self.roles

  if self.has_role? role.to_s
    self.roles.delete(role)
    self.update_attribute(:roles, self.roles)
  end
end

#role!(role) ⇒ Object Also known as: has_role!, add_role



20
21
22
23
24
25
26
27
# File 'app/models/roleable.rb', line 20

def role!(role)
  self.send(:"roles=", []) if !self.roles

  if !self.has_role? role
    self.roles << role.to_s
    self.update_attribute(:roles, self.roles)
  end
end

#role?(role) ⇒ Boolean Also known as: has_role?, is?

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'app/models/roleable.rb', line 10

def role?(role)
  if self.roles
    self.roles.include? role.to_s
  else
    false
  end
end