Class: Guacamole::Query
- Inherits:
-
Object
- Object
- Guacamole::Query
- Includes:
- Enumerable
- Defined in:
- lib/guacamole/query.rb
Overview
Build a query for ArangoDB
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Ashikawa::Core::Collection
readonly
Connection to the database.
-
#example ⇒ Hash
The example to search for.
-
#mapper ⇒ Class
readonly
The mapper class.
-
#options ⇒ Hash
private
Currently set options.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#each(&block) ⇒ Object
Iterate over the result of the query.
-
#initialize(connection, mapper) ⇒ Query
constructor
Create a new Query.
-
#limit(limit) ⇒ self
Limit the results of the query.
-
#skip(skip) ⇒ self
The number of results to skip.
Constructor Details
#initialize(connection, mapper) ⇒ Query
Create a new Query
32 33 34 35 36 |
# File 'lib/guacamole/query.rb', line 32 def initialize(connection, mapper) @connection = connection @mapper = mapper @options = {} end |
Instance Attribute Details
#connection ⇒ Ashikawa::Core::Collection (readonly)
Connection to the database
10 11 12 |
# File 'lib/guacamole/query.rb', line 10 def connection @connection end |
#example ⇒ Hash
The example to search for
20 21 22 |
# File 'lib/guacamole/query.rb', line 20 def example @example end |
#mapper ⇒ Class (readonly)
The mapper class
15 16 17 |
# File 'lib/guacamole/query.rb', line 15 def mapper @mapper end |
#options ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Currently set options
26 27 28 |
# File 'lib/guacamole/query.rb', line 26 def @options end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Is this Guacamole::Query equal to another Guacamole::Query
Two Guacamole::Query objects are equal if their examples are equal
70 71 72 73 |
# File 'lib/guacamole/query.rb', line 70 def ==(other) other.instance_of?(self.class) && example == other.example end |
#each(&block) ⇒ Object
Iterate over the result of the query
This will execute the query you have build
41 42 43 44 45 |
# File 'lib/guacamole/query.rb', line 41 def each(&block) return to_enum(__callee__) unless block_given? perfom_query ->(document) { block.call mapper.document_to_model(document) }, &block end |
#limit(limit) ⇒ self
Limit the results of the query
51 52 53 54 |
# File 'lib/guacamole/query.rb', line 51 def limit(limit) [:limit] = limit self end |
#skip(skip) ⇒ self
The number of results to skip
60 61 62 63 |
# File 'lib/guacamole/query.rb', line 60 def skip(skip) [:skip] = skip self end |