mongoid-scroll 0.3.2 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +0,0 @@
1
- module Mongoid
2
- module Criterion
3
- module Scrollable
4
- def scroll(cursor = nil, &_block)
5
- criteria = self
6
- # we don't support scrolling over a criteria with multiple fields
7
- if criteria.options[:sort] && criteria.options[:sort].keys.size != 1
8
- fail Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: criteria.options[:sort])
9
- elsif !criteria.options.key?(:sort) || criteria.options[:sort].empty?
10
- # introduce a default sort order if there's none
11
- criteria = criteria.asc(:_id)
12
- end
13
- # scroll field and direction
14
- scroll_field = criteria.options[:sort].keys.first
15
- scroll_direction = criteria.options[:sort].values.first.to_i
16
- # scroll cursor from the parameter, with value and tiebreak_id
17
- field = criteria.klass.fields[scroll_field.to_s]
18
- cursor_options = { field_type: field.type, field_name: scroll_field, direction: scroll_direction }
19
- cursor = cursor.is_a?(Mongoid::Scroll::Cursor) ? cursor : Mongoid::Scroll::Cursor.new(cursor, cursor_options)
20
- # scroll
21
- if block_given?
22
- cursor_criteria = criteria.dup
23
- cursor_criteria.selector = { '$and' => [criteria.selector, cursor.criteria] }
24
- cursor_criteria.order_by(_id: scroll_direction).each do |record|
25
- yield record, Mongoid::Scroll::Cursor.from_record(record, cursor_options)
26
- end
27
- else
28
- criteria
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,7 +0,0 @@
1
- module Mongoid
2
- module Scroll
3
- def self.mongoid3?
4
- Mongoid::VERSION =~ /^3\./
5
- end
6
- end
7
- end