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.
- checksums.yaml +5 -5
- data/.rubocop.yml +0 -2
- data/.rubocop_todo.yml +38 -17
- data/.travis.yml +31 -12
- data/CHANGELOG.md +32 -16
- data/Dangerfile +1 -0
- data/Gemfile +13 -10
- data/LICENSE.md +1 -1
- data/README.md +31 -11
- data/RELEASING.md +67 -0
- data/Rakefile +1 -1
- data/examples/mongo_ruby_driver_scroll_feed.rb +45 -0
- data/examples/mongoid_scroll_feed.rb +8 -3
- data/examples/moped_scroll_feed.rb +2 -0
- data/lib/config/locales/en.yml +1 -1
- data/lib/mongo/scrollable.rb +34 -0
- data/lib/mongoid-scroll.rb +3 -6
- data/lib/mongoid/criteria/scrollable.rb +81 -0
- data/lib/mongoid/scroll/cursor.rb +15 -11
- data/lib/mongoid/scroll/errors/base.rb +1 -1
- data/lib/mongoid/scroll/version.rb +1 -1
- data/lib/moped/scrollable.rb +7 -6
- data/mongoid-scroll.gemspec +2 -1
- data/spec/mongo/collection_view_spec.rb +126 -0
- data/spec/mongoid/criteria_spec.rb +39 -4
- data/spec/mongoid/scroll_cursor_spec.rb +25 -25
- data/spec/moped/query_spec.rb +100 -98
- data/spec/spec_helper.rb +6 -1
- data/spec/support/feed/item.rb +5 -1
- data/spec/support/feed/publisher.rb +9 -0
- data/spec/support/mongodb.rb +9 -0
- metadata +30 -11
- data/lib/mongoid/criterion/scrollable.rb +0 -33
- data/lib/mongoid/scroll/mongoid.rb +0 -7
|
@@ -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
|