Class: MongoMapper::Query

Inherits:
Object show all
Defined in:
lib/mongo_mapper/query.rb

Overview

IMPORTANT This class is private to MongoMapper and should not be considered part of MongoMapper’s public API.

Constant Summary collapse

OptionKeys =
[:fields, :select, :skip, :offset, :limit, :sort, :order]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options) ⇒ Query

Returns a new instance of Query.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
# File 'lib/mongo_mapper/query.rb', line 10

def initialize(model, options)
  raise ArgumentError, "Options must be a hash" unless options.is_a?(Hash)
  @model, @options, @conditions, @original_options = model, {}, {}, options
  separate_options_and_conditions
  add_sci_condition
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/mongo_mapper/query.rb', line 8

def model
  @model
end

Instance Method Details

#criteriaObject



17
18
19
# File 'lib/mongo_mapper/query.rb', line 17

def criteria
  to_criteria(@conditions)
end

#optionsObject



21
22
23
24
25
26
27
28
# File 'lib/mongo_mapper/query.rb', line 21

def options
  fields = @options[:fields] || @options[:select]
  skip   = @options[:skip]   || @options[:offset] || 0
  limit  = @options[:limit]  || 0
  sort   = @options[:sort]   || normalized_sort(@options[:order])

  {:fields => to_fields(fields), :skip => skip.to_i, :limit => limit.to_i, :sort => sort}
end

#to_aObject



30
31
32
# File 'lib/mongo_mapper/query.rb', line 30

def to_a
  [criteria, options]
end