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
Public Class Methods
# File lib/checkpoint/db/cartesian_select.rb, line 28 def initialize(scope: Grant) @scope = scope end
Public Instance Methods
# File lib/checkpoint/db/cartesian_select.rb, line 36 def all exec(:select) end
# File lib/checkpoint/db/cartesian_select.rb, line 48 def conditions { zone_id: :$zone_id } end
# File lib/checkpoint/db/cartesian_select.rb, line 44 def delete exec(:delete) end
# File lib/checkpoint/db/cartesian_select.rb, line 40 def first exec(:first) end
# File lib/checkpoint/db/cartesian_select.rb, line 54 def parameters { zone_id: Grant.default_zone } end
# File lib/checkpoint/db/cartesian_select.rb, line 32 def query scope.where(conditions) end
Private Instance Methods
# File lib/checkpoint/db/cartesian_select.rb, line 62 def exec(mode) query.call(mode, parameters) end
# File lib/checkpoint/db/cartesian_select.rb, line 66 def tokenize(collection) [collection].flatten.map(&:token) end