Class: Guacamole::Query

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/guacamole/query.rb

Overview

Build a query for ArangoDB

Direct Known Subclasses

AqlQuery, GraphQuery

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, mapper) ⇒ Query

Create a new Query

Parameters:

  • connection (Ashikawa::Core::Collection)

    The collection to use to talk to the database

  • mapper (Class)

    the class of the mapper to use



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

#connectionAshikawa::Core::Collection (readonly)

Connection to the database

Returns:

  • (Ashikawa::Core::Collection)


10
11
12
# File 'lib/guacamole/query.rb', line 10

def connection
  @connection
end

#exampleHash

The example to search for

Returns:

  • (Hash)

    the example



20
21
22
# File 'lib/guacamole/query.rb', line 20

def example
  @example
end

#mapperClass (readonly)

The mapper class

Returns:

  • (Class)


15
16
17
# File 'lib/guacamole/query.rb', line 15

def mapper
  @mapper
end

#optionsHash

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

Returns:

  • (Hash)


26
27
28
# File 'lib/guacamole/query.rb', line 26

def options
  @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

Parameters:

  • other (Query)

    The query to compare to



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

Parameters:

  • limit (Fixnum)

Returns:

  • (self)


51
52
53
54
# File 'lib/guacamole/query.rb', line 51

def limit(limit)
  options[:limit] = limit
  self
end

#skip(skip) ⇒ self

The number of results to skip

Parameters:

  • skip (Fixnum)

Returns:

  • (self)


60
61
62
63
# File 'lib/guacamole/query.rb', line 60

def skip(skip)
  options[:skip] = skip
  self
end