Class: Cuprum::Collections::QueryBuilder
- Inherits:
-
Object
- Object
- Cuprum::Collections::QueryBuilder
- Defined in:
- lib/cuprum/collections/query_builder.rb
Overview
Internal class that handles parsing and applying criteria to a query.
Direct Known Subclasses
Defined Under Namespace
Classes: ParseError
Instance Attribute Summary collapse
-
#base_query ⇒ Cuprum::Collections::Query
readonly
The original query.
Instance Method Summary collapse
-
#call(where:, strategy: nil) ⇒ Cuprum::Collections::Query
Returns a copy of the query updated with the generated criteria.
-
#initialize(base_query) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
Constructor Details
#initialize(base_query) ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
13 14 15 |
# File 'lib/cuprum/collections/query_builder.rb', line 13 def initialize(base_query) @base_query = base_query end |
Instance Attribute Details
#base_query ⇒ Cuprum::Collections::Query (readonly)
Returns the original query.
18 19 20 |
# File 'lib/cuprum/collections/query_builder.rb', line 18 def base_query @base_query end |
Instance Method Details
#call(where:, strategy: nil) ⇒ Cuprum::Collections::Query
Returns a copy of the query updated with the generated criteria.
Classifies the parameters to determine parsing strategy, then uses that strategy to parse the parameters into an array of criteria. Then, copies the original query and updates the copy with the parsed criteria.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cuprum/collections/query_builder.rb', line 32 def call(where:, strategy: nil) criteria = if strategy == :unsafe where else parse_criteria(strategy: strategy, where: where) end build_query(criteria) end |