Sha256: 913d64bd00d01443ba2b932de19c7f5c3477539c77f44234a755869a6fd4bb4e

Contents?: true

Size: 1.27 KB

Versions: 82

Compression:

Stored size: 1.27 KB

Contents

require "set"

module Ddr
  module Auth
    module Roles
      #
      # Wraps a set of Roles detached from a repository object
      #
      class DetachedRoleSet < RoleSet

        delegate :each, to: :role_set
        
        class << self
          # Deserialize a serialized RoleSet into a DetachedRoleSet
          def deserialize(serialized)
            role_set = serialized.map { |role_data| Role.deserialize(role_data) }
            new(role_set)
          end

          # Deserialize a JSON representation of a set of Roles into a DetachedRoleSet
          def from_json(json)
            deserialize JSON.parse(json)
          end
        end

        attr_writer :role_set

        def initialize(role_set = Set.new)
          super role_set.to_set
        end

        def grant(*roles)
          role_set.merge coerce(roles)
        end

        def revoke(*roles)
          self.role_set -= coerce(roles)
        end

        def revoke_all
          clear
        end

        def to_a
          role_set.to_a
        end

        # Merges the roles from another role set into the role set
        # @param other [Enumerable<Role>]
        # @return [DetachedRoleSet] self
        def merge(other)
          role_set.merge other
          self
        end

      end
    end
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
ddr-models-2.4.8 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.7 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.6 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.5 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.4 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.3 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.2 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.1 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.0 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.0.rc6 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.0.rc5 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.0.rc4 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.0.rc3 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.0.rc2 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.4.0.rc1 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.3.2 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.3.1 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-3.0.0.alpha.4 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-3.0.0.alpha.3 lib/ddr/auth/roles/detached_role_set.rb
ddr-models-2.3.0 lib/ddr/auth/roles/detached_role_set.rb