Module: PagesCore::HasRoles

Extended by:
ActiveSupport::Concern
Included in:
Invite, User
Defined in:
app/models/concerns/pages_core/has_roles.rb

Instance Method Summary collapse

Instance Method Details

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

Returns:

  • (Boolean)

5
6
7
# File 'app/models/concerns/pages_core/has_roles.rb', line 5

def role?(role_name)
  role_names.include?(role_name.to_s)
end

#role_namesObject


10
11
12
# File 'app/models/concerns/pages_core/has_roles.rb', line 10

def role_names
  roles.map(&:name)
end

#role_names=(names) ⇒ Object


14
15
16
17
18
19
20
21
22
23
# File 'app/models/concerns/pages_core/has_roles.rb', line 14

def role_names=(names)
  new_roles = names.map do |name|
    if role?(name)
      roles.find_by(name: name)
    else
      roles.new(name: name)
    end
  end
  self.roles = new_roles
end