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.12.7 app/models/concerns/pages_core/has_roles.rb
pages_core-3.12.6 app/models/concerns/pages_core/has_roles.rb
pages_core-3.12.5 app/models/concerns/pages_core/has_roles.rb
pages_core-3.12.4 app/models/concerns/pages_core/has_roles.rb
pages_core-3.12.3 app/models/concerns/pages_core/has_roles.rb
pages_core-3.12.2 app/models/concerns/pages_core/has_roles.rb
pages_core-3.12.1 app/models/concerns/pages_core/has_roles.rb
pages_core-3.12.0 app/models/concerns/pages_core/has_roles.rb
pages_core-3.11.3 app/models/concerns/pages_core/has_roles.rb
pages_core-3.11.2 app/models/concerns/pages_core/has_roles.rb
pages_core-3.11.1 app/models/concerns/pages_core/has_roles.rb
pages_core-3.11.0 app/models/concerns/pages_core/has_roles.rb
pages_core-3.10.2 app/models/concerns/pages_core/has_roles.rb
pages_core-3.10.1 app/models/concerns/pages_core/has_roles.rb
pages_core-3.9.2 app/models/concerns/pages_core/has_roles.rb
pages_core-3.9.1 app/models/concerns/pages_core/has_roles.rb
pages_core-3.9.0 app/models/concerns/pages_core/has_roles.rb
pages_core-3.8.3 app/models/concerns/pages_core/has_roles.rb
pages_core-3.8.2 app/models/concerns/pages_core/has_roles.rb
pages_core-3.8.1 app/models/concerns/pages_core/has_roles.rb