7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/mongoid/criteria/scrollable.rb', line 7
def scroll(cursor_or_type = nil, &_block)
cursor, cursor_type = cursor_and_type(cursor_or_type)
raise_multiple_sort_fields_error if multiple_sort_fields?
criteria = dup
criteria.merge!(default_sort) if no_sort_option?
cursor_options = build_cursor_options(criteria)
cursor = cursor.is_a?(cursor_type) ? cursor : new_cursor(cursor_type, cursor, cursor_options)
raise_mismatched_sort_fields_error!(cursor, cursor_options) if different_sort_fields?(cursor, cursor_options)
cursor_criteria = build_cursor_criteria(criteria, cursor)
if block_given?
cursor_criteria.order_by(_id: scroll_direction(criteria)).each do |record|
yield record, cursor_from_record(cursor_type, record, cursor_options)
end
else
cursor_criteria
end
end
|