mongoid-scroll 0.3.3 → 0.3.4
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 +4 -4
- data/.rubocop_todo.yml +10 -10
- data/CHANGELOG.md +6 -1
- data/LICENSE.md +1 -1
- data/README.md +25 -4
- 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/mongo/scrollable.rb +33 -0
- data/lib/mongoid-scroll.rb +2 -5
- data/lib/mongoid/criterion/scrollable.rb +2 -0
- data/lib/mongoid/scroll/cursor.rb +1 -1
- data/lib/mongoid/scroll/version.rb +1 -1
- data/lib/moped/scrollable.rb +6 -5
- data/mongoid-scroll.gemspec +1 -0
- data/spec/mongo/collection_view_spec.rb +124 -0
- data/spec/mongoid/criteria_spec.rb +1 -1
- data/spec/mongoid/scroll_cursor_spec.rb +2 -2
- data/spec/moped/query_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- metadata +31 -15
- data/lib/mongoid/scroll/mongoid.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 022e561816d188ff5a1d3e6af69004107ad165bf
|
4
|
+
data.tar.gz: 6d50c0f44d7e8ad830b0d381c4791f96425ef7cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f6faa3ae039517af97d415c096af31409203d88c563ec6169b05d9ac91e7fa56f783e6b7ad7de64454829bb0e824e96c71fedc558bbfb9b7b7be64cdf1b392f
|
7
|
+
data.tar.gz: 511e661677f4ccc5e3dce89e178a72f2aa90cb3fb6c09bd4177b444493cd6f9fd61d0104498161e8f266b3ffe0bbcfb3eb09260d868eec43f351754a41883e98
|
data/.rubocop_todo.yml
CHANGED
@@ -1,37 +1,38 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2015-
|
3
|
+
# on 2015-10-22 08:27:54 -0400 using RuboCop version 0.33.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 6
|
10
10
|
Metrics/AbcSize:
|
11
11
|
Max: 70
|
12
12
|
|
13
|
-
# Offense count:
|
13
|
+
# Offense count: 6
|
14
14
|
Metrics/CyclomaticComplexity:
|
15
15
|
Max: 11
|
16
16
|
|
17
|
-
# Offense count:
|
17
|
+
# Offense count: 107
|
18
18
|
# Configuration parameters: AllowURI, URISchemes.
|
19
19
|
Metrics/LineLength:
|
20
20
|
Max: 170
|
21
21
|
|
22
|
-
# Offense count:
|
22
|
+
# Offense count: 5
|
23
23
|
# Configuration parameters: CountComments.
|
24
24
|
Metrics/MethodLength:
|
25
|
-
Max:
|
25
|
+
Max: 25
|
26
26
|
|
27
|
-
# Offense count:
|
27
|
+
# Offense count: 4
|
28
28
|
Metrics/PerceivedComplexity:
|
29
|
-
Max:
|
29
|
+
Max: 11
|
30
30
|
|
31
31
|
# Offense count: 13
|
32
32
|
Style/Documentation:
|
33
33
|
Exclude:
|
34
34
|
- 'examples/mongoid_scroll_feed.rb'
|
35
|
+
- 'lib/mongo/scrollable.rb'
|
35
36
|
- 'lib/mongoid/criterion/scrollable.rb'
|
36
37
|
- 'lib/mongoid/scroll/cursor.rb'
|
37
38
|
- 'lib/mongoid/scroll/errors/base.rb'
|
@@ -39,7 +40,6 @@ Style/Documentation:
|
|
39
40
|
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'
|
40
41
|
- 'lib/mongoid/scroll/errors/no_such_field_error.rb'
|
41
42
|
- 'lib/mongoid/scroll/errors/unsupported_field_type_error.rb'
|
42
|
-
- 'lib/mongoid/scroll/mongoid.rb'
|
43
43
|
- 'lib/mongoid/scroll/version.rb'
|
44
44
|
- 'lib/moped/scrollable.rb'
|
45
45
|
- 'spec/support/feed/embedded_item.rb'
|
@@ -51,7 +51,7 @@ Style/FileName:
|
|
51
51
|
Exclude:
|
52
52
|
- 'lib/mongoid-scroll.rb'
|
53
53
|
|
54
|
-
# Offense count:
|
54
|
+
# Offense count: 7
|
55
55
|
# Configuration parameters: SupportedStyles.
|
56
56
|
Style/RaiseArgs:
|
57
57
|
EnforcedStyle: compact
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
0.3.4 (2015/10/22)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Added support for [mongo-ruby-driver](https://github.com/mongodb/mongo-ruby-driver), `Mongo::Collection::View`- [@dblock](https://github.com/dblock).
|
5
|
+
|
1
6
|
0.3.3 (2015/09/17)
|
2
7
|
------------------
|
3
8
|
|
4
|
-
*
|
9
|
+
* Compatibility with Mongoid 5 - [@dblock](https://github.com/dblock).
|
5
10
|
|
6
11
|
0.3.2 (2015/8/8)
|
7
12
|
----------------
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Mongoid extension that enables infinite scrolling for `Mongoid::Criteria` and `M
|
|
12
12
|
Compatibility
|
13
13
|
-------------
|
14
14
|
|
15
|
-
This gem supports Mongoid 3, 4 and 5.
|
15
|
+
This gem supports Mongoid 3, 4 and 5, Moped and Mongo-Ruby-Driver.
|
16
16
|
|
17
17
|
Demo
|
18
18
|
----
|
@@ -85,9 +85,9 @@ Feed::Item.desc(:position).scroll(saved_cursor) do |record, next_cursor|
|
|
85
85
|
end
|
86
86
|
```
|
87
87
|
|
88
|
-
### Moped
|
88
|
+
### Moped (Mongoid 3 and 4)
|
89
89
|
|
90
|
-
Scroll and save a cursor to the last item. You must also supply a `field_type` of the sort criteria.
|
90
|
+
Scroll a `Moped::Query` and save a cursor to the last item. You must also supply a `field_type` of the sort criteria.
|
91
91
|
|
92
92
|
```ruby
|
93
93
|
saved_cursor = nil
|
@@ -106,6 +106,27 @@ session[:feed_items].find.sort(position: -1).limit(5).scroll(saved_cursor, { fie
|
|
106
106
|
end
|
107
107
|
```
|
108
108
|
|
109
|
+
### Mongo-Ruby-Driver (Mongoid 5)
|
110
|
+
|
111
|
+
Scroll a `Mongo::Collection::View` and save a cursor to the last item. You must also supply a `field_type` of the sort criteria.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
saved_cursor = nil
|
115
|
+
client[:feed_items].find.sort(position: -1).limit(5).scroll(nil, { field_type: DateTime }) do |record, next_cursor|
|
116
|
+
# each record, one-by-one
|
117
|
+
saved_cursor = next_cursor
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
Resume iterating using the previously saved cursor.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
session[:feed_items].find.sort(position: -1).limit(5).scroll(saved_cursor, { field_type: DateTime }) do |record, next_cursor|
|
125
|
+
# each record, one-by-one
|
126
|
+
saved_cursor = next_cursor
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
109
130
|
Indexes and Performance
|
110
131
|
-----------------------
|
111
132
|
|
@@ -166,4 +187,4 @@ Copyright and License
|
|
166
187
|
|
167
188
|
MIT License, see [LICENSE](http://github.com/dblock/mongoid-scroll/raw/master/LICENSE.md) for details.
|
168
189
|
|
169
|
-
(c) 2013 [Daniel Doubrovkine](http://github.com/dblock), based on code by [Frank Macreery](http://github.com/macreery), [Artsy Inc.](http://artsy.net)
|
190
|
+
(c) 2013-2015 [Daniel Doubrovkine](http://github.com/dblock), based on code by [Frank Macreery](http://github.com/macreery), [Artsy Inc.](http://artsy.net)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup(:default, :development)
|
3
|
+
|
4
|
+
require 'mongoid-scroll'
|
5
|
+
require 'faker'
|
6
|
+
|
7
|
+
fail 'No Mongo Ruby Driver' unless Object.const_defined?(:Mongo)
|
8
|
+
|
9
|
+
Mongo::Logger.logger = Logger.new($stdout)
|
10
|
+
Mongo::Logger.logger.level = Logger::INFO
|
11
|
+
|
12
|
+
Mongoid.connect_to 'mongoid_scroll_demo'
|
13
|
+
Mongoid.purge!
|
14
|
+
|
15
|
+
# total items to insert
|
16
|
+
total_items = 20
|
17
|
+
# a MongoDB query will be executed every scroll_by items
|
18
|
+
scroll_by = 7
|
19
|
+
|
20
|
+
# insert items with a position out-of-order
|
21
|
+
rands = (0..total_items).to_a.sort { rand }[0..total_items]
|
22
|
+
total_items.times do
|
23
|
+
Mongoid.default_client['feed_items'].insert_one(title: Faker::Lorem.sentence, position: rands.pop)
|
24
|
+
end
|
25
|
+
|
26
|
+
Mongoid.default_client['feed_items'].indexes.create_one(position: 1, _id: 1)
|
27
|
+
|
28
|
+
total_shown = 0
|
29
|
+
next_cursor = nil
|
30
|
+
loop do
|
31
|
+
current_cursor = next_cursor
|
32
|
+
next_cursor = nil
|
33
|
+
Mongoid.default_client['feed_items'].find.limit(scroll_by).sort(position: 1).scroll(current_cursor, field_type: Integer, field_name: 'position') do |item, cursor|
|
34
|
+
puts "#{item['position']}: #{item['title']}"
|
35
|
+
next_cursor = cursor
|
36
|
+
total_shown += 1
|
37
|
+
end
|
38
|
+
break unless next_cursor
|
39
|
+
# destroy an item just for the heck of it, scroll is not affected
|
40
|
+
item = Mongoid.default_client['feed_items'].find.sort(position: 1).first
|
41
|
+
Mongoid.default_client['feed_items'].find(_id: item['_id']).delete_one
|
42
|
+
end
|
43
|
+
|
44
|
+
# this will be 20
|
45
|
+
puts "Shown #{total_shown} items."
|
@@ -4,6 +4,14 @@ Bundler.setup(:default, :development)
|
|
4
4
|
require 'mongoid-scroll'
|
5
5
|
require 'faker'
|
6
6
|
|
7
|
+
if defined?(Moped)
|
8
|
+
Moped.logger = Logger.new($stdout)
|
9
|
+
Moped.logger.level = Logger::DEBUG
|
10
|
+
else
|
11
|
+
Mongoid.logger.level = Logger::INFO
|
12
|
+
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
|
13
|
+
end
|
14
|
+
|
7
15
|
Mongoid.connect_to 'mongoid_scroll_demo'
|
8
16
|
Mongoid.purge!
|
9
17
|
|
@@ -27,9 +35,6 @@ total_items.times do |_i|
|
|
27
35
|
Feed::Item.create! title: Faker::Lorem.sentence, position: rands.pop
|
28
36
|
end
|
29
37
|
|
30
|
-
Moped.logger = Logger.new($stdout)
|
31
|
-
Moped.logger.level = Logger::DEBUG
|
32
|
-
|
33
38
|
Feed::Item.create_indexes
|
34
39
|
|
35
40
|
total_shown = 0
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Mongo
|
2
|
+
module Scrollable
|
3
|
+
def scroll(cursor = nil, options = nil, &_block)
|
4
|
+
view = self
|
5
|
+
# we don't support scrolling over a view with multiple fields
|
6
|
+
fail Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: view.sort) if view.sort && view.sort.keys.size != 1
|
7
|
+
# scroll field and direction
|
8
|
+
scroll_field = view.sort ? view.sort.keys.first : :_id
|
9
|
+
scroll_direction = view.sort ? view.sort.values.first.to_i : 1
|
10
|
+
# scroll cursor from the parameter, with value and tiebreak_id
|
11
|
+
options = { field_type: BSON::ObjectId } unless options
|
12
|
+
cursor_options = { field_name: scroll_field, direction: scroll_direction }.merge(options)
|
13
|
+
cursor = cursor.is_a?(Mongoid::Scroll::Cursor) ? cursor : Mongoid::Scroll::Cursor.new(cursor, cursor_options)
|
14
|
+
# make a view
|
15
|
+
view = Mongo::Collection::View.new(
|
16
|
+
view.collection,
|
17
|
+
view.selector.merge(cursor.criteria),
|
18
|
+
sort: (view.sort || {}).merge(_id: scroll_direction),
|
19
|
+
skip: skip,
|
20
|
+
limit: limit)
|
21
|
+
# scroll
|
22
|
+
if block_given?
|
23
|
+
view.each do |record|
|
24
|
+
yield record, Mongoid::Scroll::Cursor.from_record(record, cursor_options)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
view
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Mongo::Collection::View.send(:include, Mongo::Scrollable)
|
data/lib/mongoid-scroll.rb
CHANGED
@@ -3,13 +3,10 @@ require 'i18n'
|
|
3
3
|
I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
|
4
4
|
|
5
5
|
require 'mongoid'
|
6
|
+
require 'mongoid-compatibility'
|
6
7
|
require 'mongoid/scroll/version'
|
7
|
-
require 'mongoid/scroll/mongoid'
|
8
8
|
require 'mongoid/scroll/errors'
|
9
9
|
require 'mongoid/scroll/cursor'
|
10
|
-
|
11
10
|
require 'moped/scrollable' if Object.const_defined?(:Moped)
|
11
|
+
require 'mongo/scrollable' if Object.const_defined?(:Mongo)
|
12
12
|
require 'mongoid/criterion/scrollable'
|
13
|
-
|
14
|
-
Moped::Query.send(:include, Moped::Scrollable) if Object.const_defined?(:Moped)
|
15
|
-
Mongoid::Criteria.send(:include, Mongoid::Criterion::Scrollable)
|
@@ -44,7 +44,7 @@ module Mongoid
|
|
44
44
|
id = parts[-1]
|
45
45
|
value = parts[0...-1].join(':')
|
46
46
|
@value = Mongoid::Scroll::Cursor.parse_field_value(field_type, field_name, value)
|
47
|
-
if Mongoid::
|
47
|
+
if Mongoid::Compatibility::Version.mongoid3?
|
48
48
|
@tiebreak_id = Moped::BSON::ObjectId(id)
|
49
49
|
else
|
50
50
|
@tiebreak_id = BSON::ObjectId.from_string(id)
|
data/lib/moped/scrollable.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Moped
|
2
2
|
module Scrollable
|
3
3
|
def scroll(cursor = nil, options = nil, &_block)
|
4
|
-
options
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end unless options
|
4
|
+
unless options
|
5
|
+
bson_type = Mongoid::Compatibility::Version.mongoid3? ? Moped::BSON::ObjectId : BSON::ObjectId
|
6
|
+
options = { field_type: bson_type }
|
7
|
+
end
|
9
8
|
query = Query.new(collection, operation.selector.dup)
|
10
9
|
query.operation.skip = operation.skip
|
11
10
|
query.operation.limit = operation.limit
|
@@ -35,3 +34,5 @@ module Moped
|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
37
|
+
|
38
|
+
Moped::Query.send(:include, Moped::Scrollable)
|
data/mongoid-scroll.gemspec
CHANGED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongo::Collection::View do
|
4
|
+
context 'scrollable' do
|
5
|
+
subject do
|
6
|
+
Mongoid.default_client['feed_items'].find
|
7
|
+
end
|
8
|
+
it ':scroll' do
|
9
|
+
expect(subject).to respond_to(:scroll)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
context 'with multiple sort fields' do
|
13
|
+
subject do
|
14
|
+
Mongoid.default_client['feed_items'].find.sort(name: 1, value: -1)
|
15
|
+
end
|
16
|
+
it 'raises Mongoid::Scroll::Errors::MultipleSortFieldsError' do
|
17
|
+
expect { subject.scroll }.to raise_error Mongoid::Scroll::Errors::MultipleSortFieldsError,
|
18
|
+
/You're attempting to scroll over data with a sort order that includes multiple fields: name, value./
|
19
|
+
end
|
20
|
+
end
|
21
|
+
context 'with no sort' do
|
22
|
+
subject do
|
23
|
+
Mongoid.default_client['feed_items'].find
|
24
|
+
end
|
25
|
+
it 'adds a default sort by _id' do
|
26
|
+
expect(subject.scroll.sort).to eq('_id' => 1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context 'with data' do
|
30
|
+
before :each do
|
31
|
+
10.times do |i|
|
32
|
+
Mongoid.default_client['feed_items'].insert_one(
|
33
|
+
a_string: i.to_s,
|
34
|
+
a_integer: i,
|
35
|
+
a_datetime: DateTime.mongoize(DateTime.new(2013, i + 1, 21, 1, 42, 3, 'UTC')),
|
36
|
+
a_date: Date.mongoize(Date.new(2013, i + 1, 21)),
|
37
|
+
a_time: Time.mongoize(Time.at(Time.now.to_i + i))
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context 'default' do
|
42
|
+
it 'scrolls all' do
|
43
|
+
records = []
|
44
|
+
Mongoid.default_client['feed_items'].find.scroll do |record, _next_cursor|
|
45
|
+
records << record
|
46
|
+
end
|
47
|
+
expect(records.size).to eq 10
|
48
|
+
expect(records).to eq Mongoid.default_client['feed_items'].find.to_a
|
49
|
+
end
|
50
|
+
end
|
51
|
+
{ a_string: String, a_integer: Integer, a_date: Date, a_datetime: DateTime }.each_pair do |field_name, field_type|
|
52
|
+
context field_type do
|
53
|
+
it 'scrolls all with a block' do
|
54
|
+
records = []
|
55
|
+
Mongoid.default_client['feed_items'].find.sort(field_name => 1).scroll(nil, field_type: field_type) do |record, _next_cursor|
|
56
|
+
records << record
|
57
|
+
end
|
58
|
+
expect(records.size).to eq 10
|
59
|
+
expect(records).to eq Mongoid.default_client['feed_items'].find.to_a
|
60
|
+
end
|
61
|
+
it 'scrolls all with a break' do
|
62
|
+
records = []
|
63
|
+
cursor = nil
|
64
|
+
Mongoid.default_client['feed_items'].find.sort(field_name => 1).limit(5).scroll(nil, field_type: field_type) do |record, next_cursor|
|
65
|
+
records << record
|
66
|
+
cursor = next_cursor
|
67
|
+
end
|
68
|
+
expect(records.size).to eq 5
|
69
|
+
Mongoid.default_client['feed_items'].find.sort(field_name => 1).scroll(cursor, field_type: field_type) do |record, next_cursor|
|
70
|
+
records << record
|
71
|
+
cursor = next_cursor
|
72
|
+
end
|
73
|
+
expect(records.size).to eq 10
|
74
|
+
expect(records).to eq Mongoid.default_client['feed_items'].find.to_a
|
75
|
+
end
|
76
|
+
it 'scrolls in descending order' do
|
77
|
+
records = []
|
78
|
+
Mongoid.default_client['feed_items'].find.sort(field_name => -1).limit(3).scroll(nil, field_type: field_type, field_name: field_name) do |record, _next_cursor|
|
79
|
+
records << record
|
80
|
+
end
|
81
|
+
expect(records.size).to eq 3
|
82
|
+
expect(records).to eq Mongoid.default_client['feed_items'].find.sort(field_name => -1).limit(3).to_a
|
83
|
+
end
|
84
|
+
it 'map' do
|
85
|
+
record = Mongoid.default_client['feed_items'].find.limit(3).scroll(nil, field_type: field_type, field_name: field_name).map { |r| r }.last
|
86
|
+
cursor = Mongoid::Scroll::Cursor.from_record(record, field_type: field_type, field_name: field_name)
|
87
|
+
expect(cursor).to_not be nil
|
88
|
+
expect(cursor.to_s.split(':')).to eq [
|
89
|
+
Mongoid::Scroll::Cursor.transform_field_value(field_type, field_name, record[field_name.to_s]).to_s,
|
90
|
+
record['_id'].to_s
|
91
|
+
]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
context 'with overlapping data' do
|
97
|
+
before :each do
|
98
|
+
3.times { Feed::Item.create! a_integer: 5 }
|
99
|
+
Feed::Item.first.update_attributes!(name: Array(1000).join('a'))
|
100
|
+
end
|
101
|
+
it 'natural order is different from order by id' do
|
102
|
+
# natural order isn't necessarily going to be the same as _id order
|
103
|
+
# if a document is updated and grows in size, it may need to be relocated and
|
104
|
+
# thus cause the natural order to change
|
105
|
+
expect(Feed::Item.order_by('$natural' => 1).to_a).to_not eq Feed::Item.order_by(_id: 1).to_a
|
106
|
+
end
|
107
|
+
[{ a_integer: 1 }, { a_integer: -1 }].each do |sort_order|
|
108
|
+
it "scrolls by #{sort_order}" do
|
109
|
+
records = []
|
110
|
+
cursor = nil
|
111
|
+
Mongoid.default_client['feed_items'].find.sort(sort_order).limit(2).scroll do |record, next_cursor|
|
112
|
+
records << record
|
113
|
+
cursor = next_cursor
|
114
|
+
end
|
115
|
+
expect(records.size).to eq 2
|
116
|
+
Mongoid.default_client['feed_items'].find.sort(sort_order).scroll(cursor) do |record, _next_cursor|
|
117
|
+
records << record
|
118
|
+
end
|
119
|
+
expect(records.size).to eq 3
|
120
|
+
expect(records).to eq Mongoid.default_client['feed_items'].find.sort(sort_order.merge(_id: sort_order[:a_integer])).to_a
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end if Object.const_defined?(:Mongo)
|
@@ -134,7 +134,7 @@ describe Mongoid::Criteria do
|
|
134
134
|
criteria = Feed::Item.where(:a_time.gt => Time.new(2013, 7, 22, 1, 2, 3))
|
135
135
|
feed_item_1 = Feed::Item.where(name: 'Feed Item 1').first
|
136
136
|
cursor_input = "#{feed_item_1.id}:#{feed_item_1.id}"
|
137
|
-
field_type = Mongoid::
|
137
|
+
field_type = Mongoid::Compatibility::Version.mongoid3? ? Moped::BSON::ObjectId : BSON::ObjectId
|
138
138
|
cursor_options = { field_type: field_type, field_name: '_id', direction: 1 }
|
139
139
|
cursor = Mongoid::Scroll::Cursor.new(cursor_input, cursor_options)
|
140
140
|
records = []
|
@@ -17,14 +17,14 @@ describe Mongoid::Scroll::Cursor do
|
|
17
17
|
end
|
18
18
|
context 'an id field cursor' do
|
19
19
|
let(:feed_item) { Feed::Item.create!(a_string: 'astring') }
|
20
|
-
field_type = Mongoid::
|
20
|
+
field_type = Mongoid::Compatibility::Version.mongoid3? ? Moped::BSON::ObjectId : BSON::ObjectId
|
21
21
|
subject do
|
22
22
|
Mongoid::Scroll::Cursor.new "#{feed_item.id}:#{feed_item.id}", field_name: '_id', field_type: field_type, direction: 1
|
23
23
|
end
|
24
24
|
its(:value) { should eq feed_item.id.to_s }
|
25
25
|
its(:tiebreak_id) { should eq feed_item.id }
|
26
26
|
its(:criteria) do
|
27
|
-
if Mongoid::
|
27
|
+
if Mongoid::Compatibility::Version.mongoid3?
|
28
28
|
should eq('$or' => [
|
29
29
|
{ '_id' => { '$gt' => Moped::BSON::ObjectId("#{feed_item.id}") } }
|
30
30
|
])
|
data/spec/moped/query_spec.rb
CHANGED
@@ -117,7 +117,7 @@ describe Moped::Query do
|
|
117
117
|
records << record
|
118
118
|
end
|
119
119
|
expect(records.size).to eq 3
|
120
|
-
expect(records).to eq Mongoid.default_session['feed_items'].find.sort(_id: sort_order[:a_integer]).to_a
|
120
|
+
expect(records).to eq Mongoid.default_session['feed_items'].find.sort(sort_order.merge(_id: sort_order[:a_integer])).to_a
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,6 +15,10 @@ Mongoid.configure do |config|
|
|
15
15
|
end
|
16
16
|
|
17
17
|
RSpec.configure do |config|
|
18
|
+
config.before :all do
|
19
|
+
Mongoid.logger.level = Logger::INFO
|
20
|
+
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
|
21
|
+
end
|
18
22
|
config.before :each do
|
19
23
|
Mongoid.purge!
|
20
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-scroll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
@@ -9,34 +9,48 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '3.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '3.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: mongoid-compatibility
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: i18n
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
31
45
|
requirements:
|
32
|
-
- -
|
46
|
+
- - '>='
|
33
47
|
- !ruby/object:Gem::Version
|
34
48
|
version: '0'
|
35
49
|
type: :runtime
|
36
50
|
prerelease: false
|
37
51
|
version_requirements: !ruby/object:Gem::Requirement
|
38
52
|
requirements:
|
39
|
-
- -
|
53
|
+
- - '>='
|
40
54
|
- !ruby/object:Gem::Version
|
41
55
|
version: '0'
|
42
56
|
description:
|
@@ -45,20 +59,22 @@ executables: []
|
|
45
59
|
extensions: []
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .rubocop.yml
|
65
|
+
- .rubocop_todo.yml
|
66
|
+
- .travis.yml
|
53
67
|
- CHANGELOG.md
|
54
68
|
- Gemfile
|
55
69
|
- LICENSE.md
|
56
70
|
- README.md
|
57
71
|
- RELEASING.md
|
58
72
|
- Rakefile
|
73
|
+
- examples/mongo_ruby_driver_scroll_feed.rb
|
59
74
|
- examples/mongoid_scroll_feed.rb
|
60
75
|
- examples/moped_scroll_feed.rb
|
61
76
|
- lib/config/locales/en.yml
|
77
|
+
- lib/mongo/scrollable.rb
|
62
78
|
- lib/mongoid-scroll.rb
|
63
79
|
- lib/mongoid/criterion/scrollable.rb
|
64
80
|
- lib/mongoid/scroll/cursor.rb
|
@@ -68,11 +84,11 @@ files:
|
|
68
84
|
- lib/mongoid/scroll/errors/multiple_sort_fields_error.rb
|
69
85
|
- lib/mongoid/scroll/errors/no_such_field_error.rb
|
70
86
|
- lib/mongoid/scroll/errors/unsupported_field_type_error.rb
|
71
|
-
- lib/mongoid/scroll/mongoid.rb
|
72
87
|
- lib/mongoid/scroll/version.rb
|
73
88
|
- lib/mongoid_scroll.rb
|
74
89
|
- lib/moped/scrollable.rb
|
75
90
|
- mongoid-scroll.gemspec
|
91
|
+
- spec/mongo/collection_view_spec.rb
|
76
92
|
- spec/mongoid/criteria_spec.rb
|
77
93
|
- spec/mongoid/scroll_cursor_spec.rb
|
78
94
|
- spec/mongoid/scroll_spec.rb
|
@@ -90,17 +106,17 @@ require_paths:
|
|
90
106
|
- lib
|
91
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
108
|
requirements:
|
93
|
-
- -
|
109
|
+
- - '>='
|
94
110
|
- !ruby/object:Gem::Version
|
95
111
|
version: '0'
|
96
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
113
|
requirements:
|
98
|
-
- -
|
114
|
+
- - '>='
|
99
115
|
- !ruby/object:Gem::Version
|
100
116
|
version: 1.3.6
|
101
117
|
requirements: []
|
102
118
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.4.5
|
104
120
|
signing_key:
|
105
121
|
specification_version: 4
|
106
122
|
summary: Mongoid extensions to enable infinite scroll.
|