Class: Checkpoint::DB::CartesianSelect
- Inherits:
-
Object
- Object
- Checkpoint::DB::CartesianSelect
- 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
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #all ⇒ Object
- #conditions ⇒ Object
- #delete ⇒ Object
- #first ⇒ Object
-
#initialize(scope: Grant) ⇒ CartesianSelect
constructor
A new instance of CartesianSelect.
- #parameters ⇒ Object
- #query ⇒ Object
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
#scope ⇒ Object (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
#all ⇒ Object
36 37 38 |
# File 'lib/checkpoint/db/cartesian_select.rb', line 36 def all exec(:select) end |
#conditions ⇒ Object
48 49 50 51 52 |
# File 'lib/checkpoint/db/cartesian_select.rb', line 48 def conditions { zone_id: :$zone_id } end |
#delete ⇒ Object
44 45 46 |
# File 'lib/checkpoint/db/cartesian_select.rb', line 44 def delete exec(:delete) end |
#first ⇒ Object
40 41 42 |
# File 'lib/checkpoint/db/cartesian_select.rb', line 40 def first exec(:first) end |
#parameters ⇒ Object
54 55 56 57 58 |
# File 'lib/checkpoint/db/cartesian_select.rb', line 54 def parameters { zone_id: Grant.default_zone } end |
#query ⇒ Object
32 33 34 |
# File 'lib/checkpoint/db/cartesian_select.rb', line 32 def query scope.where(conditions) end |