Class: Checkpoint::DB::CartesianSelect

Inherits:
Object
  • Object
show all
Defined in:
lib/checkpoint/db/cartesian_select.rb

Overview

Helper for querying by cross-products across sets of parameters, especially for grants.

This class is called CartesianSelect because the logical search space is the Cartesian product, for example, of agents X credentials X resources. All grants in that space would be selected.

This is a base class to support convenient variations for searching in different scenarios. It is unlikely to be very useful in its own right, but provides structure for specific subclasses. For example, Query::ACR searches for grants when agents, credentials, and resources are all known, as when checking authorization. When seeking to list agents that could take a given action on a resource, Query::CR would be useful.

Subclasses should extends the conditions and parameters methods to supply the placeholders and matching values. The Params class is helpful for that purpose.

The queries are ultimately implemented with an IN clause for each key in the conditions with binding expressions in the way Sequel expects them.

Direct Known Subclasses

Query::AC, Query::ACR, Query::AR, Query::CR

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope: Grant) ⇒ CartesianSelect

Returns a new instance of CartesianSelect.



28
29
30
# File 'lib/checkpoint/db/cartesian_select.rb', line 28

def initialize(scope: Grant)
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



26
27
28
# File 'lib/checkpoint/db/cartesian_select.rb', line 26

def scope
  @scope
end

Instance Method Details

#allObject



36
37
38
# File 'lib/checkpoint/db/cartesian_select.rb', line 36

def all
  exec(:select)
end

#conditionsObject



48
49
50
51
52
# File 'lib/checkpoint/db/cartesian_select.rb', line 48

def conditions
  {
    zone_id: :$zone_id
  }
end

#deleteObject



44
45
46
# File 'lib/checkpoint/db/cartesian_select.rb', line 44

def delete
  exec(:delete)
end

#firstObject



40
41
42
# File 'lib/checkpoint/db/cartesian_select.rb', line 40

def first
  exec(:first)
end

#parametersObject



54
55
56
57
58
# File 'lib/checkpoint/db/cartesian_select.rb', line 54

def parameters
  {
    zone_id: Grant.default_zone
  }
end

#queryObject



32
33
34
# File 'lib/checkpoint/db/cartesian_select.rb', line 32

def query
  scope.where(conditions)
end