Module: PagesCore::HasRoles
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/pages_core/has_roles.rb
Instance Method Summary collapse
- #role?(role_name) ⇒ Boolean (also: #has_role?)
- #role_names ⇒ Object
- #role_names=(names) ⇒ Object
Instance Method Details
#role?(role_name) ⇒ Boolean Also known as: has_role?
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_names ⇒ Object
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:) else roles.new(name:) end end end |