Sha256: 22e7526b2bdcaea9ee0fbb9e30508fcef7cac73b81bd8324b899e52cc25faf88

Contents?: true

Size: 930 Bytes

Versions: 32

Compression:

Stored size: 930 Bytes

Contents

require "set"
require "virtus"

module Ddr::Auth
  module Roles
    extend Deprecation
    #
    # Wraps a set of Roles
    #
    class RoleSet
      include Virtus.model
      include Enumerable
      include ActiveModel::Serializers::JSON

      attribute :roles, Set[Role]

      delegate :where, :agent, :scope, :role_type,
               :in_policy_scope, :in_resource_scope,
               to: :query

      delegate :each, :empty?, :clear, to: :roles

      def self.from_json(json)
        new.from_json(json.present? ? json : "{}")
      end

      def ==(other)
        instance_of?(other.class) && self.roles == other.roles
      end

      def merge(other)
        self.roles += other.roles
        self
      end

      def permissions
        map(&:permissions).flatten.uniq
      end

      def agents
        map(&:agent).uniq
      end

      def query
        RoleSetQuery.new(self)
      end

    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
ddr-models-3.0.8 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.7 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.6 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.5 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.4 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.3 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.2 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.1 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.rc6 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.rc5 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.rc4 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.rc3 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.rc2 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.rc1 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.22 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.21 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.20 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.18 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.17 lib/ddr/auth/roles/role_set.rb