Class: Arkenstone::QueryBuilder
- Inherits:
-
Object
- Object
- Arkenstone::QueryBuilder
- Defined in:
- lib/arkenstone/query_builder.rb
Overview
Builder
Builds up the query from the DSL and returns a ruby hash.
Instance Method Summary collapse
-
#_and(*vals) ⇒ Object
Finds entries that match all expressions in the value provided.
-
#_gt(val) ⇒ Object
Finds entries who’s values for a column are greater than the value provided.
-
#_gte(val) ⇒ Object
Finds entries who’s values for a column are greater than or equal to the value provided.
-
#_in(value_array) ⇒ Object
Finds the entries that have a value for a column in the provided
value_array
. -
#_include(values) ⇒ Object
Adds include statements for the database endpoint to parse.
-
#_limit(max) ⇒ Object
Sets a max number of results to return.
-
#_lt(val) ⇒ Object
Finds entries who’s values for a column are less than the value provided.
-
#_lte(val) ⇒ Object
Finds entries who’s values for a column are less than or equal to the value provided.
-
#_not(*vals) ⇒ Object
Finds entries that do not match any expression in the value provided.
-
#_or(*vals) ⇒ Object
Finds entries that match any expression in the value provided.
-
#build ⇒ Object
Main entry point for processing the DSL.
-
#initialize ⇒ QueryBuilder
constructor
Initializes the @hash variable, which is used to build complex queries.
Constructor Details
#initialize ⇒ QueryBuilder
Initializes the @hash variable, which is used to build complex queries.
9 10 11 |
# File 'lib/arkenstone/query_builder.rb', line 9 def initialize @cache = {} end |
Instance Method Details
#_and(*vals) ⇒ Object
Finds entries that match all expressions in the value provided.
46 47 48 |
# File 'lib/arkenstone/query_builder.rb', line 46 def _and(*vals) evaluate_expression '$and', vals end |
#_gt(val) ⇒ Object
Finds entries who’s values for a column are greater than the value provided.
26 27 28 |
# File 'lib/arkenstone/query_builder.rb', line 26 def _gt(val) { '$gt' => val } end |
#_gte(val) ⇒ Object
Finds entries who’s values for a column are greater than or equal to the value provided.
31 32 33 |
# File 'lib/arkenstone/query_builder.rb', line 31 def _gte(val) { '$gte' => val } end |
#_in(value_array) ⇒ Object
Finds the entries that have a value for a column in the provided value_array
.
21 22 23 |
# File 'lib/arkenstone/query_builder.rb', line 21 def _in(value_array) { '$in' => value_array } end |
#_include(values) ⇒ Object
Adds include statements for the database endpoint to parse.
61 62 63 |
# File 'lib/arkenstone/query_builder.rb', line 61 def _include(values) @cache = evaluate_expression '$include', values end |
#_limit(max) ⇒ Object
Sets a max number of results to return.
66 67 68 |
# File 'lib/arkenstone/query_builder.rb', line 66 def _limit(max) @cache = evaluate_expression '$limit', max end |
#_lt(val) ⇒ Object
Finds entries who’s values for a column are less than the value provided.
36 37 38 |
# File 'lib/arkenstone/query_builder.rb', line 36 def _lt(val) { '$lt' => val } end |
#_lte(val) ⇒ Object
Finds entries who’s values for a column are less than or equal to the value provided.
41 42 43 |
# File 'lib/arkenstone/query_builder.rb', line 41 def _lte(val) { '$lte' => val } end |
#_not(*vals) ⇒ Object
Finds entries that do not match any expression in the value provided.
56 57 58 |
# File 'lib/arkenstone/query_builder.rb', line 56 def _not(*vals) evaluate_expression '$not', vals end |
#_or(*vals) ⇒ Object
Finds entries that match any expression in the value provided.
51 52 53 |
# File 'lib/arkenstone/query_builder.rb', line 51 def _or(*vals) evaluate_expression '$or', vals end |
#build ⇒ Object
Main entry point for processing the DSL.
14 15 16 17 18 |
# File 'lib/arkenstone/query_builder.rb', line 14 def build(&) result = instance_eval(&) result = flush.merge result unless @cache.empty? result.to_json end |