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)


7
8
9
# File 'app/models/concerns/pages_core/has_roles.rb', line 7

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

#role_namesObject



12
13
14
# File 'app/models/concerns/pages_core/has_roles.rb', line 12

def role_names
  roles.map(&:name)
end

#role_names=(names) ⇒ Object



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

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