Class: Cuprum::Collections::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cuprum/collections/query_builder.rb

Overview

Internal class that handles parsing and applying criteria to a query.

Direct Known Subclasses

Basic::QueryBuilder

Defined Under Namespace

Classes: ParseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_query) ⇒ QueryBuilder

Returns a new instance of QueryBuilder.

Parameters:



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_queryCuprum::Collections::Query (readonly)

Returns the original query.

Returns:



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.

Parameters:

  • strategy (Symbol, nil) (defaults to: nil)

    The specified strategy for parsing the given filter into criteria. If nil, the builder will attempt to guess the strategy based on the given filter.

  • where (Object)

    The filter used to match items in the collection.

Returns:



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