Sha256: d7365d1d7e9ee8f3eee0bda3c06b7835d5340c29a0ca83236141dfb6f6410b94

Contents?: true

Size: 465 Bytes

Versions: 22

Compression:

Stored size: 465 Bytes

Contents

# frozen_string_literal: true

module PagesCore
  module HasRoles
    extend ActiveSupport::Concern

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

    def role_names
      roles.map(&:name)
    end

    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
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
pages_core-3.8.0 app/models/concerns/pages_core/has_roles.rb
pages_core-3.7.0 app/models/concerns/pages_core/has_roles.rb