Class: MongoMapper::FinderOptions
- Defined in:
- lib/mongo_mapper/finder_options.rb
Overview
Controls the parsing and handling of options used by finders.
Important Note
This class is private to MongoMapper and should not be considered part of MongoMapper’s public API. Some documentation herein, however, may prove useful for understanding how MongoMapper handles the parsing of finder conditions and options.
Constant Summary collapse
- OptionKeys =
[:fields, :select, :skip, :offset, :limit, :sort, :order]
Instance Method Summary collapse
-
#criteria ⇒ Hash
Mongo compatible criteria options.
-
#initialize(model, options) ⇒ FinderOptions
constructor
A new instance of FinderOptions.
-
#options ⇒ Hash
Mongo compatible options.
-
#to_a ⇒ Array<Hash>
Mongo criteria and options enclosed in an Array.
Constructor Details
#initialize(model, options) ⇒ FinderOptions
Returns a new instance of FinderOptions.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mongo_mapper/finder_options.rb', line 15 def initialize(model, ) raise ArgumentError, "Options must be a hash" unless .is_a?(Hash) = .symbolize_keys @model = model @options = {} @conditions = .delete(:conditions) || {} .each_pair do |key, value| if OptionKeys.include?(key) @options[key] = value else @conditions[key] = value end end add_sci_scope end |
Instance Method Details
#criteria ⇒ Hash
Returns Mongo compatible criteria options.
37 38 39 |
# File 'lib/mongo_mapper/finder_options.rb', line 37 def criteria to_mongo_criteria(@conditions) end |
#options ⇒ Hash
Returns Mongo compatible options.
42 43 44 45 46 47 48 49 |
# File 'lib/mongo_mapper/finder_options.rb', line 42 def fields = @options.delete(:fields) || @options.delete(:select) skip = @options.delete(:skip) || @options.delete(:offset) || 0 limit = @options.delete(:limit) || 0 sort = @options.delete(:sort) || convert_order_to_sort(@options.delete(:order)) {:fields => to_mongo_fields(fields), :skip => skip.to_i, :limit => limit.to_i, :sort => sort} end |