Sha256: 22baf2a576603e70e9dbcd90ce54fb0151f0beff3dd4a2f092dc9669dd2a01d3

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Checkpoint::DB
  module Query
    # A query object based on credentials and resources.
    #
    # This query finds grants for any supplied credentials, for any supplied
    # resources. Its primary purpose is to find which agents have been granted
    # a given credential on a resource.
    #
    # It can take single items or arrays and converts them all to their tokens
    # for query purposes.
    class CR < CartesianSelect
      attr_reader :credentials, :resources

      def initialize(credentials, resources, scope: Grant)
        super(scope: scope)
        @credentials = tokenize(credentials)
        @resources   = tokenize(resources)
      end

      def conditions
        super.merge(
          credential_token: credential_params.placeholders,
          resource_token:   resource_params.placeholders
        )
      end

      def parameters
        super.merge(Hash[
          credential_params.values +
          resource_params.values
        ])
      end

      protected

      def credential_params
        Params.new(credentials, 'ct')
      end

      def resource_params
        Params.new(resources, 'rt')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
checkpoint-1.1.3 lib/checkpoint/db/query/cr.rb
checkpoint-1.1.2 lib/checkpoint/db/query/cr.rb
checkpoint-1.1.1 lib/checkpoint/db/query/cr.rb
checkpoint-1.1.0 lib/checkpoint/db/query/cr.rb