Module: CoreModels::Models::Concerns::RoleConcerns

Included in:
Role
Defined in:
lib/core_models/models/concerns/role_concerns.rb

Instance Method Summary collapse

Instance Method Details

#add_permission=(name) ⇒ Object



17
18
19
# File 'lib/core_models/models/concerns/role_concerns.rb', line 17

def add_permission=(name)
  self.permissions << self.permissions.klass.find_by(permission_name: name)
end

#change_permissions=(names) ⇒ Object



21
22
23
# File 'lib/core_models/models/concerns/role_concerns.rb', line 21

def change_permissions=(names)
  self.permissions = self.permissions.klass.where(permission_name: names)
end

#has_group?(name) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/core_models/models/concerns/role_concerns.rb', line 9

def has_group?(name)
  self.groups.where(group_name: name).any?
end

#has_permission?(name) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/core_models/models/concerns/role_concerns.rb', line 5

def has_permission?(name)
  self.permissions.where(permission_name: name).any?
end

#permission_namesObject



13
14
15
# File 'lib/core_models/models/concerns/role_concerns.rb', line 13

def permission_names
  self.permissions.pluck(:permission_name)
end

#remove_permission=(name) ⇒ Object



25
26
27
# File 'lib/core_models/models/concerns/role_concerns.rb', line 25

def remove_permission=(name)
  self.permissions.delete(self.permissions.klass.find_by(permission_name: name))
end