Class: Role

Inherits:
ApplicationRecord show all
Defined in:
app/models/role.rb

Overview

NOTE add the person object you want to attach role to…

Class Method Summary collapse

Class Method Details

.add_admin(person) ⇒ Object


18
19
20
# File 'app/models/role.rb', line 18

def self.add_admin(person)
  find_or_create_by(person_id: person.id, name: "admin")
end

.add_moderator(person) ⇒ Object


34
35
36
# File 'app/models/role.rb', line 34

def self.add_moderator(person)
  find_or_create_by(person_id: person.id, name: "moderator")
end

.add_spotlight(person) ⇒ Object


46
47
48
# File 'app/models/role.rb', line 46

def self.add_spotlight(person)
  find_or_create_by(person_id: person.id, name: "spotlight")
end

.is_admin?(person) ⇒ Boolean

Returns:

  • (Boolean)

14
15
16
# File 'app/models/role.rb', line 14

def self.is_admin?(person)
  exists?(person_id: person.id, name: "admin")
end

.moderator?(person) ⇒ Boolean

Returns:

  • (Boolean)

26
27
28
# File 'app/models/role.rb', line 26

def self.moderator?(person)
  moderators.exists?(person_id: person.id)
end

.moderator_only?(person) ⇒ Boolean

Returns:

  • (Boolean)

30
31
32
# File 'app/models/role.rb', line 30

def self.moderator_only?(person)
  exists?(person_id: person.id, name: "moderator")
end

.remove_admin(person) ⇒ Object


22
23
24
# File 'app/models/role.rb', line 22

def self.remove_admin(person)
  find_by(person_id: person.id, name: "admin").destroy
end

.remove_moderator(person) ⇒ Object


38
39
40
# File 'app/models/role.rb', line 38

def self.remove_moderator(person)
  find_by(person_id: person.id, name: "moderator").destroy
end

.remove_spotlight(person) ⇒ Object


50
51
52
# File 'app/models/role.rb', line 50

def self.remove_spotlight(person)
  find_by(person_id: person.id, name: "spotlight").destroy
end

.spotlight?(person) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
# File 'app/models/role.rb', line 42

def self.spotlight?(person)
  exists?(person_id: person.id, name: "spotlight")
end