Class: MongoMapper::Query
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
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #criteria ⇒ Object
-
#initialize(model, options) ⇒ Query
constructor
A new instance of Query.
- #options ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(model, options) ⇒ Query
Returns a new instance of Query.
10 11 12 13 14 15 |
# File 'lib/mongo_mapper/query.rb', line 10 def initialize(model, ) raise ArgumentError, "Options must be a hash" unless .is_a?(Hash) @model, @options, @conditions, @original_options = model, {}, {}, add_sci_condition end |
Instance Attribute Details
#model ⇒ Object (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
#criteria ⇒ Object
17 18 19 |
# File 'lib/mongo_mapper/query.rb', line 17 def criteria to_criteria(@conditions) end |
#options ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/mongo_mapper/query.rb', line 21 def 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_a ⇒ Object
30 31 32 |
# File 'lib/mongo_mapper/query.rb', line 30 def to_a [criteria, ] end |