Class: Checkpoint::DB::Query::AR

Inherits:
CartesianSelect show all
Defined in:
lib/checkpoint/db/query/ar.rb

Overview

A query object based on agents and resources.

This query finds grants for any supplied agents, for any supplied resources. Its primary purpose is to find which credentials have been granted to an agent on a given resource.

It can take single items or arrays and converts them all to their tokens for query purposes.

Instance Attribute Summary collapse

Attributes inherited from CartesianSelect

#scope

Instance Method Summary collapse

Methods inherited from CartesianSelect

#all, #delete, #first, #query

Constructor Details

#initialize(agents, resources, scope: Grant) ⇒ AR

Returns a new instance of AR.



16
17
18
19
20
# File 'lib/checkpoint/db/query/ar.rb', line 16

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

Instance Attribute Details

#agentsObject (readonly)

Returns the value of attribute agents.



14
15
16
# File 'lib/checkpoint/db/query/ar.rb', line 14

def agents
  @agents
end

#resourcesObject (readonly)

Returns the value of attribute resources.



14
15
16
# File 'lib/checkpoint/db/query/ar.rb', line 14

def resources
  @resources
end

Instance Method Details

#conditionsObject



22
23
24
25
26
27
# File 'lib/checkpoint/db/query/ar.rb', line 22

def conditions
  super.merge(
    agent_token:      agent_params.placeholders,
    resource_token:   resource_params.placeholders
  )
end

#parametersObject



29
30
31
32
33
34
# File 'lib/checkpoint/db/query/ar.rb', line 29

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