Sha256: 57adab440672e25401285f5bf07277d25a28f5f9371a3fd0efd8defd0ee3b6db

Contents?: true

Size: 455 Bytes

Versions: 7

Compression:

Stored size: 455 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:)
        else
          roles.new(name:)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pages_core-3.15.5 app/models/concerns/pages_core/has_roles.rb
pages_core-3.15.4 app/models/concerns/pages_core/has_roles.rb
pages_core-3.15.3 app/models/concerns/pages_core/has_roles.rb
pages_core-3.15.2 app/models/concerns/pages_core/has_roles.rb
pages_core-3.15.1 app/models/concerns/pages_core/has_roles.rb
pages_core-3.14.0 app/models/concerns/pages_core/has_roles.rb
pages_core-3.13.0 app/models/concerns/pages_core/has_roles.rb