Class: Checkpoint::Permits::Query
- Inherits:
-
Object
- Object
- Checkpoint::Permits::Query
- Defined in:
- lib/checkpoint/permits.rb
Overview
A query object based on agents, credentials, and resources.
This is a helper to capture a set of agents, credentials, and resources, and manage assembly of placeholder variables and binding expressions in the way Sequel expects them. It can take single items or arrays and converts them all to their tokens for query purposes.
Instance Attribute Summary collapse
-
#agents ⇒ Object
readonly
Returns the value of attribute agents.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #agent_params ⇒ Object
- #conditions ⇒ Object
- #credential_params ⇒ Object
- #first ⇒ Object
-
#initialize(agents, credentials, resources, scope: Checkpoint::DB::Permit) ⇒ Query
constructor
A new instance of Query.
- #parameters ⇒ Object
- #query ⇒ Object
- #resource_params ⇒ Object
- #select ⇒ Object
Constructor Details
#initialize(agents, credentials, resources, scope: Checkpoint::DB::Permit) ⇒ Query
Returns a new instance of Query.
44 45 46 47 48 49 |
# File 'lib/checkpoint/permits.rb', line 44 def initialize(agents, credentials, resources, scope: Checkpoint::DB::Permit) @agents = tokenize(agents) @credentials = tokenize(credentials) @resources = tokenize(resources) @scope = scope end |
Instance Attribute Details
#agents ⇒ Object (readonly)
Returns the value of attribute agents.
42 43 44 |
# File 'lib/checkpoint/permits.rb', line 42 def agents @agents end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
42 43 44 |
# File 'lib/checkpoint/permits.rb', line 42 def credentials @credentials end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
42 43 44 |
# File 'lib/checkpoint/permits.rb', line 42 def resources @resources end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
42 43 44 |
# File 'lib/checkpoint/permits.rb', line 42 def scope @scope end |
Instance Method Details
#agent_params ⇒ Object
79 80 81 |
# File 'lib/checkpoint/permits.rb', line 79 def agent_params Params.new(agents, 'at') end |
#conditions ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/checkpoint/permits.rb', line 63 def conditions { agent_token: agent_params.placeholders, credential_token: credential_params.placeholders, resource_token: resource_params.placeholders, zone_id: :$zone_id } end |
#credential_params ⇒ Object
83 84 85 |
# File 'lib/checkpoint/permits.rb', line 83 def credential_params Params.new(credentials, 'ct') end |
#first ⇒ Object
59 60 61 |
# File 'lib/checkpoint/permits.rb', line 59 def first exec(:first) end |
#parameters ⇒ Object
72 73 74 75 76 77 |
# File 'lib/checkpoint/permits.rb', line 72 def parameters (agent_params.values + credential_params.values + resource_params.values + [[:zone_id, DB::Permit.default_zone]]).to_h end |
#query ⇒ Object
51 52 53 |
# File 'lib/checkpoint/permits.rb', line 51 def query scope.where(conditions) end |
#resource_params ⇒ Object
87 88 89 |
# File 'lib/checkpoint/permits.rb', line 87 def resource_params Params.new(resources, 'rt') end |
#select ⇒ Object
55 56 57 |
# File 'lib/checkpoint/permits.rb', line 55 def select exec(:select) end |