class Checkpoint::DB::CartesianSelect

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.

Attributes

scope[R]

Public Class Methods

new(scope: Grant) click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 28
def initialize(scope: Grant)
  @scope = scope
end

Public Instance Methods

all() click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 36
def all
  exec(:select)
end
conditions() click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 48
def conditions
  {
    zone_id: :$zone_id
  }
end
delete() click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 44
def delete
  exec(:delete)
end
first() click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 40
def first
  exec(:first)
end
parameters() click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 54
def parameters
  {
    zone_id: Grant.default_zone
  }
end
query() click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 32
def query
  scope.where(conditions)
end

Private Instance Methods

exec(mode) click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 62
def exec(mode)
  query.call(mode, parameters)
end
tokenize(collection) click to toggle source
# File lib/checkpoint/db/cartesian_select.rb, line 66
def tokenize(collection)
  [collection].flatten.map(&:token)
end