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.0.beta.16 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.15 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.14 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.13 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.12 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.11 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.10 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.9 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.8 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.7 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.6 lib/ddr/auth/roles/role_set.rb
ddr-models-3.0.0.beta.4 lib/ddr/auth/roles/role_set.rb