mongoid-scroll 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +20 -2
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +153 -35
- data/CHANGELOG.md +15 -5
- data/Gemfile +4 -4
- data/README.md +24 -36
- data/RELEASING.md +1 -4
- data/Rakefile +3 -3
- data/UPGRADING.md +21 -1
- data/examples/{mongoid_scroll_feed.rb → feed.rb} +3 -3
- data/lib/config/locales/en.yml +4 -1
- data/lib/mongoid/criteria/scrollable/iterator.rb +19 -0
- data/lib/mongoid/criteria/scrollable.rb +28 -8
- data/lib/mongoid/scroll/base64_encoded_cursor.rb +8 -6
- data/lib/mongoid/scroll/base_cursor.rb +12 -11
- data/lib/mongoid/scroll/cursor.rb +5 -5
- data/lib/mongoid/scroll/errors/base.rb +4 -4
- data/lib/mongoid/scroll/errors/mismatched_sort_fields_error.rb +1 -3
- data/lib/mongoid/scroll/errors/multiple_sort_fields_error.rb +1 -3
- data/lib/mongoid/scroll/errors/unsupported_type_error.rb +11 -0
- data/lib/mongoid/scroll/errors.rb +1 -0
- data/lib/mongoid/scroll/version.rb +1 -1
- data/lib/mongoid-scroll.rb +1 -2
- data/mongoid-scroll.gemspec +3 -3
- data/spec/mongoid/base64_encoded_cursor_spec.rb +148 -77
- data/spec/mongoid/criteria_spec.rb +108 -37
- data/spec/mongoid/cursor_spec.rb +112 -63
- data/spec/mongoid/scroll_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -2
- data/spec/support/feed/embedded_item.rb +2 -0
- data/spec/support/feed/item.rb +1 -1
- metadata +12 -26
- data/examples/mongo_ruby_driver_scroll_feed.rb +0 -45
- data/lib/mongo/scrollable.rb +0 -39
- data/spec/mongo/collection_view_spec.rb +0 -143
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6408a43ccf6d68cedb7f2cfa984be3f3e66cf63f29c79eaaa506a8eb671da84b
|
4
|
+
data.tar.gz: 44b25144b153ef375a1425b61e1a431b10c8eaa71293c246d13d550bdfe168ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebab5c9fd5bf4de86d4e5c8305b67dea439842c57b335d9934a29c611029683cccaa8b059ffefeb7e308c832b6a8fc54de399dc828075c157b7c94aacdd48143
|
7
|
+
data.tar.gz: c187f3dfb04d7908c7332b1bec0d0a0c535125fcd232161faf8f17da65e121bd9b5168e7a703c25894d0495411737f6c6ea470bb8279f51f1d4d385b1e8728be
|
data/.github/workflows/ci.yml
CHANGED
@@ -7,8 +7,6 @@ jobs:
|
|
7
7
|
strategy:
|
8
8
|
matrix:
|
9
9
|
entry:
|
10
|
-
- { ruby: '2.6', mongodb: '4.4', mongoid: '5' }
|
11
|
-
- { ruby: '3.2', mongodb: '6.0', mongoid: '5' }
|
12
10
|
- { ruby: '2.7', mongodb: '4.4', mongoid: '6' }
|
13
11
|
- { ruby: '2.7', mongodb: '4.4', mongoid: '7' }
|
14
12
|
- { ruby: '3.0', mongodb: '4.4', mongoid: '6' }
|
@@ -18,6 +16,9 @@ jobs:
|
|
18
16
|
- { ruby: '3.1', mongodb: '4.4', mongoid: '8' }
|
19
17
|
- { ruby: '3.2', mongodb: '5.0', mongoid: '8' }
|
20
18
|
- { ruby: '3.2', mongodb: '6.0', mongoid: '8' }
|
19
|
+
- { ruby: '3.2', mongodb: '7.0', mongoid: '8' }
|
20
|
+
- { ruby: '3.3', mongodb: '6.0', mongoid: '9' }
|
21
|
+
- { ruby: '3.3', mongodb: '7.0', mongoid: '9' }
|
21
22
|
name: test (ruby=${{ matrix.entry.ruby }}, mongodb=${{ matrix.entry.mongodb }}), mongoid=${{ matrix.entry.mongoid }})
|
22
23
|
env:
|
23
24
|
MONGOID_VERSION: ${{ matrix.entry.mongoid }}
|
@@ -34,3 +35,20 @@ jobs:
|
|
34
35
|
bundler-cache: true
|
35
36
|
- name: Run tests
|
36
37
|
run: bundle exec rspec
|
38
|
+
- name: Run examples
|
39
|
+
run: bundle exec ruby examples/feed.rb
|
40
|
+
- name: Report Coverage
|
41
|
+
uses: coverallsapp/github-action@v2
|
42
|
+
with:
|
43
|
+
flag-name: run-${{ join(matrix.*, '-') }}
|
44
|
+
parallel: true
|
45
|
+
|
46
|
+
upload-coverage:
|
47
|
+
needs: test
|
48
|
+
if: ${{ always() }}
|
49
|
+
runs-on: ubuntu-latest
|
50
|
+
steps:
|
51
|
+
- name: Upload Code Coverage Report
|
52
|
+
uses: coverallsapp/github-action@v2
|
53
|
+
with:
|
54
|
+
parallel-finished: true
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,59 +1,159 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2024-09-07 13:11:15 UTC using RuboCop version 1.66.1.
|
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:
|
10
|
-
# Configuration parameters: Include.
|
11
|
-
# Include:
|
12
|
-
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: Severity, Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
13
|
Exclude:
|
14
|
-
- '
|
14
|
+
- 'mongoid-scroll.gemspec'
|
15
15
|
|
16
|
-
# Offense count:
|
17
|
-
|
18
|
-
|
16
|
+
# Offense count: 1
|
17
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
18
|
+
Lint/NonDeterministicRequireOrder:
|
19
|
+
Exclude:
|
20
|
+
- 'spec/spec_helper.rb'
|
19
21
|
|
20
|
-
# Offense count:
|
21
|
-
# Configuration parameters:
|
22
|
-
Metrics/
|
23
|
-
Max:
|
22
|
+
# Offense count: 7
|
23
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Max: 28
|
24
26
|
|
25
27
|
# Offense count: 1
|
26
|
-
# Configuration parameters: CountComments.
|
28
|
+
# Configuration parameters: CountComments, CountAsOne.
|
27
29
|
Metrics/ClassLength:
|
28
|
-
Max:
|
30
|
+
Max: 108
|
29
31
|
|
30
32
|
# Offense count: 5
|
33
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
31
34
|
Metrics/CyclomaticComplexity:
|
32
35
|
Max: 13
|
33
36
|
|
34
|
-
# Offense count: 153
|
35
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
36
|
-
# URISchemes: http, https
|
37
|
-
Metrics/LineLength:
|
38
|
-
Max: 252
|
39
|
-
|
40
37
|
# Offense count: 7
|
41
|
-
# Configuration parameters: CountComments.
|
38
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
42
39
|
Metrics/MethodLength:
|
43
|
-
Max:
|
40
|
+
Max: 24
|
44
41
|
|
45
|
-
# Offense count:
|
42
|
+
# Offense count: 3
|
43
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
46
44
|
Metrics/PerceivedComplexity:
|
47
|
-
Max:
|
45
|
+
Max: 13
|
46
|
+
|
47
|
+
# Offense count: 1
|
48
|
+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
49
|
+
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
|
50
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
51
|
+
Naming/FileName:
|
52
|
+
Exclude:
|
53
|
+
- 'Rakefile.rb'
|
54
|
+
- 'lib/mongoid-scroll.rb'
|
55
|
+
|
56
|
+
# Offense count: 3
|
57
|
+
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
|
58
|
+
# SupportedStyles: snake_case, normalcase, non_integer
|
59
|
+
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
|
60
|
+
Naming/VariableNumber:
|
61
|
+
Exclude:
|
62
|
+
- 'spec/mongoid/criteria_spec.rb'
|
63
|
+
|
64
|
+
# Offense count: 34
|
65
|
+
# Configuration parameters: Prefixes, AllowedPatterns.
|
66
|
+
# Prefixes: when, with, without
|
67
|
+
RSpec/ContextWording:
|
68
|
+
Exclude:
|
69
|
+
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
|
70
|
+
- 'spec/mongoid/criteria_spec.rb'
|
71
|
+
- 'spec/mongoid/cursor_spec.rb'
|
72
|
+
|
73
|
+
# Offense count: 34
|
74
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
75
|
+
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
|
76
|
+
# SupportedStyles: described_class, explicit
|
77
|
+
RSpec/DescribedClass:
|
78
|
+
Exclude:
|
79
|
+
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
|
80
|
+
- 'spec/mongoid/cursor_spec.rb'
|
81
|
+
|
82
|
+
# Offense count: 17
|
83
|
+
# Configuration parameters: CountAsOne.
|
84
|
+
RSpec/ExampleLength:
|
85
|
+
Max: 18
|
86
|
+
|
87
|
+
# Offense count: 3
|
88
|
+
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
|
89
|
+
RSpec/IndexedLet:
|
90
|
+
Exclude:
|
91
|
+
- 'spec/mongoid/criteria_spec.rb'
|
92
|
+
|
93
|
+
# Offense count: 2
|
94
|
+
# Configuration parameters: AssignmentOnly.
|
95
|
+
RSpec/InstanceVariable:
|
96
|
+
Exclude:
|
97
|
+
- 'spec/mongoid/criteria_spec.rb'
|
48
98
|
|
49
99
|
# Offense count: 11
|
100
|
+
RSpec/MultipleExpectations:
|
101
|
+
Max: 4
|
102
|
+
|
103
|
+
# Offense count: 4
|
104
|
+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
|
105
|
+
# SupportedStyles: always, named_only
|
106
|
+
RSpec/NamedSubject:
|
107
|
+
Exclude:
|
108
|
+
- 'spec/mongoid/criteria_spec.rb'
|
109
|
+
|
110
|
+
# Offense count: 3
|
111
|
+
# Configuration parameters: AllowedGroups.
|
112
|
+
RSpec/NestedGroups:
|
113
|
+
Max: 4
|
114
|
+
|
115
|
+
# Offense count: 3
|
116
|
+
# Configuration parameters: AllowedPatterns.
|
117
|
+
# AllowedPatterns: ^expect_, ^assert_
|
118
|
+
RSpec/NoExpectationExample:
|
119
|
+
Exclude:
|
120
|
+
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
|
121
|
+
|
122
|
+
# Offense count: 4
|
123
|
+
RSpec/RepeatedDescription:
|
124
|
+
Exclude:
|
125
|
+
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
|
126
|
+
|
127
|
+
# Offense count: 4
|
128
|
+
RSpec/RepeatedExample:
|
129
|
+
Exclude:
|
130
|
+
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
|
131
|
+
|
132
|
+
# Offense count: 3
|
133
|
+
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
|
134
|
+
# Include: **/*_spec.rb
|
135
|
+
RSpec/SpecFilePathFormat:
|
136
|
+
Exclude:
|
137
|
+
- '**/spec/routing/**/*'
|
138
|
+
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
|
139
|
+
- 'spec/mongoid/cursor_spec.rb'
|
140
|
+
- 'spec/mongoid/scroll_spec.rb'
|
141
|
+
|
142
|
+
# Offense count: 1
|
143
|
+
# This cop supports safe autocorrection (--autocorrect).
|
144
|
+
Rake/Desc:
|
145
|
+
Exclude:
|
146
|
+
- 'Rakefile'
|
147
|
+
|
148
|
+
# Offense count: 12
|
149
|
+
# Configuration parameters: AllowedConstants.
|
50
150
|
Style/Documentation:
|
51
151
|
Exclude:
|
52
152
|
- 'spec/**/*'
|
53
153
|
- 'test/**/*'
|
54
|
-
- 'examples/
|
55
|
-
- 'lib/mongo/scrollable.rb'
|
154
|
+
- 'examples/feed.rb'
|
56
155
|
- 'lib/mongoid/criteria/scrollable.rb'
|
156
|
+
- 'lib/mongoid/criteria/scrollable/iterator.rb'
|
57
157
|
- 'lib/mongoid/scroll/base_cursor.rb'
|
58
158
|
- 'lib/mongoid/scroll/cursor.rb'
|
59
159
|
- 'lib/mongoid/scroll/errors/base.rb'
|
@@ -62,22 +162,40 @@ Style/Documentation:
|
|
62
162
|
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'
|
63
163
|
- 'lib/mongoid/scroll/errors/no_such_field_error.rb'
|
64
164
|
- 'lib/mongoid/scroll/errors/unsupported_field_type_error.rb'
|
165
|
+
- 'lib/mongoid/scroll/errors/unsupported_type_error.rb'
|
65
166
|
|
66
|
-
# Offense count:
|
67
|
-
#
|
68
|
-
#
|
69
|
-
|
70
|
-
|
71
|
-
|
167
|
+
# Offense count: 34
|
168
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
169
|
+
# Configuration parameters: EnforcedStyle.
|
170
|
+
# SupportedStyles: always, always_true, never
|
171
|
+
Style/FrozenStringLiteralComment:
|
172
|
+
Enabled: false
|
72
173
|
|
73
174
|
# Offense count: 1
|
175
|
+
# This cop supports safe autocorrection (--autocorrect).
|
74
176
|
Style/MultilineTernaryOperator:
|
75
177
|
Exclude:
|
76
178
|
- 'lib/mongoid/scroll/cursor.rb'
|
77
179
|
|
78
180
|
# Offense count: 3
|
79
|
-
#
|
80
|
-
# Configuration parameters:
|
181
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
182
|
+
# Configuration parameters: AllowedCompactTypes.
|
81
183
|
# SupportedStyles: compact, exploded
|
82
184
|
Style/RaiseArgs:
|
83
185
|
EnforcedStyle: compact
|
186
|
+
|
187
|
+
# Offense count: 2
|
188
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
189
|
+
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
|
190
|
+
# AllowedMethods: present?, blank?, presence, try, try!
|
191
|
+
Style/SafeNavigation:
|
192
|
+
Exclude:
|
193
|
+
- 'lib/mongoid/scroll/errors/mismatched_sort_fields_error.rb'
|
194
|
+
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'
|
195
|
+
|
196
|
+
# Offense count: 36
|
197
|
+
# This cop supports safe autocorrection (--autocorrect).
|
198
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
199
|
+
# URISchemes: http, https
|
200
|
+
Layout/LineLength:
|
201
|
+
Max: 252
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
### 2.0.0 (2024/09/07)
|
2
|
+
|
3
|
+
* [#38](https://github.com/mongoid/mongoid-scroll/pull/38): Add `previous_cursor` - [@GCorbel](https://github.com/GCorbel).
|
4
|
+
* [#42](https://github.com/mongoid/mongoid-scroll/pull/42): Add `first_cursor` - [@GCorbel](https://github.com/GCorbel).
|
5
|
+
* [#43](https://github.com/mongoid/mongoid-scroll/pull/43): Add `current_cursor` - [@GCorbel](https://github.com/GCorbel).
|
6
|
+
* [#44](https://github.com/mongoid/mongoid-scroll/pull/44): Drop support for Mogoid 5 and Mongo Ruby Driver - [@dblock](https://github.com/dblock).
|
7
|
+
* [#45](https://github.com/mongoid/mongoid-scroll/pull/45): Add support for Mogoid 9 - [@dblock](https://github.com/dblock).
|
8
|
+
* [#46](https://github.com/mongoid/mongoid-scroll/pull/46): Upgrade RuboCop to 1.66.1 - [@dblock](https://github.com/dblock).
|
9
|
+
* [#47](https://github.com/mongoid/mongoid-scroll/pull/47): Add code coverage - [@dblock](https://github.com/dblock).
|
10
|
+
|
1
11
|
### 1.0.1 (2023/03/15)
|
2
12
|
|
3
13
|
* [#36](https://github.com/mongoid/mongoid-scroll/pull/36): Keep millisecond precision on time fields - [@FabienChaynes](https://github.com/FabienChaynes).
|
@@ -9,8 +19,8 @@
|
|
9
19
|
* [#29](https://github.com/mongoid/mongoid-scroll/pull/29): Add ability to include the current record to the cursor - [@FabienChaynes](https://github.com/FabienChaynes).
|
10
20
|
* [#30](https://github.com/mongoid/mongoid-scroll/pull/30): Prevent discrepancy between the original sort and the cursor sort - [@FabienChaynes](https://github.com/FabienChaynes).
|
11
21
|
* [#32](https://github.com/mongoid/mongoid-scroll/pull/32): Add Base64 serialization for cursors - [@FabienChaynes](https://github.com/FabienChaynes).
|
12
|
-
* [#33](https://github.com/mongoid/mongoid-scroll/pull/33):
|
13
|
-
* [#34](https://github.com/mongoid/mongoid-scroll/pull/34):
|
22
|
+
* [#33](https://github.com/mongoid/mongoid-scroll/pull/33): Remove support for Mongoid 3, 4 and Moped - [@dblock](https://github.com/dblock).
|
23
|
+
* [#34](https://github.com/mongoid/mongoid-scroll/pull/34): Add support for Mongoid 8 - [@dblock](https://github.com/dblock).
|
14
24
|
|
15
25
|
### 0.3.7 (2021/06/01)
|
16
26
|
|
@@ -25,7 +35,7 @@
|
|
25
35
|
### 0.3.5 (2016/09/27)
|
26
36
|
|
27
37
|
* [#11](https://github.com/mongoid/mongoid-scroll/pull/11): Compatibility with Mongoid 6 - [@dblock](https://github.com/dblock).
|
28
|
-
* [#12](https://github.com/mongoid/mongoid-scroll/pull/12):
|
38
|
+
* [#12](https://github.com/mongoid/mongoid-scroll/pull/12): Add Danger, PR linter - [@dblock](https://github.com/dblock).
|
29
39
|
|
30
40
|
### 0.3.4 (2015/10/22)
|
31
41
|
|
@@ -48,7 +58,7 @@
|
|
48
58
|
### 0.3.0 (2014/1/7)
|
49
59
|
|
50
60
|
* Compatibility with Mongoid 4.x - [@dblock](https://github.com/dblock).
|
51
|
-
*
|
61
|
+
* Implemenet Rubocop, Ruby linter - [@dblock](https://github.com/dblock).
|
52
62
|
|
53
63
|
### 0.2.1 (2013/3/21)
|
54
64
|
|
@@ -56,7 +66,7 @@
|
|
56
66
|
|
57
67
|
### 0.2.0 (2013/3/14)
|
58
68
|
|
59
|
-
*
|
69
|
+
* Extend `Moped::Query` with `scroll` - [@dblock](https://github.com/dblock).
|
60
70
|
* `Mongoid::Scroll::Cursor.from_record` can now be called with either a Mongoid field or `field_type` and `field_name` in the `options` hash - [@dblock](https://github.com/dblock).
|
61
71
|
|
62
72
|
### 0.1.0 (2013/2/14)
|
data/Gemfile
CHANGED
@@ -7,19 +7,19 @@ when 'HEAD' then gem 'mongoid', github: 'mongodb/mongoid'
|
|
7
7
|
when /8/ then gem 'mongoid', '~> 8.0'
|
8
8
|
when /7/ then gem 'mongoid', '~> 7.0'
|
9
9
|
when /6/ then gem 'mongoid', '~> 6.0'
|
10
|
-
when /5/ then
|
11
|
-
gem 'bigdecimal', '1.3.5'
|
12
|
-
gem 'mongoid', '~> 5.0'
|
13
10
|
else gem 'mongoid', version
|
14
11
|
end
|
15
12
|
|
16
13
|
group :development, :test do
|
17
14
|
gem 'bundler'
|
15
|
+
gem 'coveralls_reborn', require: false
|
18
16
|
gem 'database_cleaner', '~> 1.8.5'
|
19
17
|
gem 'faker'
|
20
18
|
gem 'mongoid-danger', '~> 0.2.0', require: false
|
21
19
|
gem 'rake'
|
22
20
|
gem 'rspec', '~> 3.0'
|
23
21
|
gem 'rspec-its'
|
24
|
-
gem 'rubocop', '
|
22
|
+
gem 'rubocop', '1.66.1'
|
23
|
+
gem 'rubocop-rake'
|
24
|
+
gem 'rubocop-rspec'
|
25
25
|
end
|
data/README.md
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
- [The Problem](#the-problem)
|
5
5
|
- [Installation](#installation)
|
6
6
|
- [Usage](#usage)
|
7
|
-
- [Mongoid](#mongoid)
|
8
|
-
- [Mongo-Ruby-Driver (Mongoid 5)](#mongo-ruby-driver-mongoid-5)
|
9
7
|
- [Indexes and Performance](#indexes-and-performance)
|
10
8
|
- [Cursors](#cursors)
|
11
9
|
- [Standard Cursor](#standard-cursor)
|
@@ -17,20 +15,18 @@
|
|
17
15
|
|
18
16
|
[![Gem Version](https://badge.fury.io/rb/mongoid-scroll.svg)](https://badge.fury.io/rb/mongoid-scroll)
|
19
17
|
[![Build Status](https://github.com/mongoid/mongoid-scroll/actions/workflows/ci.yml/badge.svg)](https://github.com/mongoid/mongoid-scroll/actions/workflows/ci.yml)
|
20
|
-
[![
|
18
|
+
[![Coverage Status](https://coveralls.io/repos/github/mongoid/mongoid-scroll/badge.svg?branch=master)](https://coveralls.io/github/mongoid/mongoid-scroll?branch=master)
|
21
19
|
[![Code Climate](https://codeclimate.com/github/mongoid/mongoid-scroll.svg)](https://codeclimate.com/github/mongoid/mongoid-scroll)
|
22
20
|
|
23
21
|
Mongoid extension that enables infinite scrolling for `Mongoid::Criteria` and `Mongo::Collection::View`.
|
24
22
|
|
25
23
|
## Compatibility
|
26
24
|
|
27
|
-
This gem supports Mongoid
|
25
|
+
This gem supports Mongoid 6, 7, 8 and 9.
|
28
26
|
|
29
27
|
## Demo
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
There're also two code samples for Mongoid in [examples](examples). Run `bundle exec ruby examples/mongoid_scroll_feed.rb`.
|
29
|
+
Take a look at [this example](examples/feed.rb). Try with with `bundle exec ruby examples/feed.rb`.
|
34
30
|
|
35
31
|
## The Problem
|
36
32
|
|
@@ -51,16 +47,16 @@ gem 'mongoid-scroll'
|
|
51
47
|
|
52
48
|
## Usage
|
53
49
|
|
54
|
-
### Mongoid
|
55
|
-
|
56
50
|
A sample model.
|
57
51
|
|
58
52
|
```ruby
|
59
53
|
module Feed
|
60
54
|
class Item
|
61
55
|
include Mongoid::Document
|
56
|
+
|
62
57
|
field :title, type: String
|
63
58
|
field :position, type: Integer
|
59
|
+
|
64
60
|
index({ position: 1, _id: 1 })
|
65
61
|
end
|
66
62
|
end
|
@@ -69,48 +65,40 @@ end
|
|
69
65
|
Scroll by `:position` and save a cursor to the last item.
|
70
66
|
|
71
67
|
```ruby
|
72
|
-
|
73
|
-
Feed::Item.desc(:position).limit(5).scroll do |record, next_cursor|
|
74
|
-
# each record, one-by-one
|
75
|
-
saved_cursor = next_cursor
|
76
|
-
end
|
77
|
-
```
|
68
|
+
saved_iterator = nil
|
78
69
|
|
79
|
-
|
80
|
-
|
81
|
-
```ruby
|
82
|
-
Feed::Item.desc(:position).limit(5).scroll(saved_cursor) do |record, next_cursor|
|
70
|
+
Feed::Item.desc(:position).limit(5).scroll do |record, iterator|
|
83
71
|
# each record, one-by-one
|
84
|
-
|
72
|
+
saved_iterator = iterator
|
85
73
|
end
|
86
74
|
```
|
87
75
|
|
88
|
-
|
76
|
+
Resume iterating using the saved cursor and save the cursor to go backwards.
|
89
77
|
|
90
78
|
```ruby
|
91
|
-
Feed::Item.desc(:position).scroll(
|
79
|
+
Feed::Item.desc(:position).limit(5).scroll(saved_iterator.next_cursor) do |record, iterator|
|
92
80
|
# each record, one-by-one
|
81
|
+
saved_iterator = iterator
|
93
82
|
end
|
94
83
|
```
|
95
84
|
|
96
|
-
|
97
|
-
|
98
|
-
Scroll a `Mongo::Collection::View` and save a cursor to the last item. You must also supply a `field_type` of the sort criteria.
|
85
|
+
Loop over the first records again.
|
99
86
|
|
100
87
|
```ruby
|
101
|
-
|
102
|
-
client[:feed_items].find.sort(position: -1).limit(5).scroll(nil, { field_type: DateTime }) do |record, next_cursor|
|
88
|
+
Feed::Item.desc(:position).limit(5).scroll(saved_iterator.previous_cursor) do |record, iterator|
|
103
89
|
# each record, one-by-one
|
104
|
-
|
90
|
+
saved_iterator = iterator
|
105
91
|
end
|
106
92
|
```
|
107
93
|
|
108
|
-
|
94
|
+
Use `saved_iterator.first_cursor` to loop over the first records or `saved_iterator.current_cursor` to loop over the same records again.
|
95
|
+
|
96
|
+
The iteration finishes when no more records are available. You can also finish iterating over the remaining records by omitting the query limit.
|
109
97
|
|
110
98
|
```ruby
|
111
|
-
|
99
|
+
Feed::Item.desc(:position).limit(5).scroll(saved_iterator.next_cursor) do |record, iterator|
|
112
100
|
# each record, one-by-one
|
113
|
-
|
101
|
+
saved_iterator = iterator
|
114
102
|
end
|
115
103
|
```
|
116
104
|
|
@@ -148,7 +136,7 @@ end
|
|
148
136
|
|
149
137
|
## Cursors
|
150
138
|
|
151
|
-
You can use `Mongoid::Scroll::Cursor.from_record` to generate a cursor. A cursor points at the last record of the
|
139
|
+
You can use `Mongoid::Scroll::Cursor.from_record` to generate a cursor. A cursor points at the last record of the iteration and unlike MongoDB cursors will not expire.
|
152
140
|
|
153
141
|
```ruby
|
154
142
|
record = Feed::Item.desc(:position).limit(3).last
|
@@ -179,15 +167,15 @@ Feed::Item.desc(:created_at).scroll(cursor) # Raises a Mongoid::Scroll::Errors::
|
|
179
167
|
|
180
168
|
### Standard Cursor
|
181
169
|
|
182
|
-
The `Mongoid::Scroll::Cursor` encodes a value and a tiebreak ID separated by `:`, and does not include other options, such as scroll direction. Take extra care not to pass a cursor into a scroll with different options.
|
170
|
+
The `Mongoid::Scroll::Cursor` encodes a value and a tiebreak ID separated by `:`, and does not include other options, such as scroll direction. Take extra care not to pass a cursor into a scroll with different options.
|
183
171
|
|
184
172
|
### Base64 Encoded Cursor
|
185
173
|
|
186
174
|
The `Mongoid::Scroll::Base64EncodedCursor` can be used instead of `Mongoid::Scroll::Cursor` to generate a base64-encoded string (using RFC 4648) containing all the information needed to rebuild a cursor.
|
187
175
|
|
188
176
|
```ruby
|
189
|
-
Feed::Item.desc(:position).limit(5).scroll(Mongoid::Scroll::Base64EncodedCursor) do |record,
|
190
|
-
# next_cursor is of type Mongoid::Scroll::Base64EncodedCursor
|
177
|
+
Feed::Item.desc(:position).limit(5).scroll(Mongoid::Scroll::Base64EncodedCursor) do |record, iterator|
|
178
|
+
# iterator.next_cursor is of type Mongoid::Scroll::Base64EncodedCursor
|
191
179
|
end
|
192
180
|
```
|
193
181
|
|
@@ -199,4 +187,4 @@ Fork the project. Make your feature addition or bug fix with tests. Send a pull
|
|
199
187
|
|
200
188
|
MIT License, see [LICENSE](http://github.com/mongoid/mongoid-scroll/raw/master/LICENSE.md) for details.
|
201
189
|
|
202
|
-
(c) 2013-
|
190
|
+
(c) 2013-2024 [Daniel Doubrovkine](http://github.com/dblock), based on code by [Frank Macreery](http://github.com/macreery), [Artsy Inc.](http://artsy.net)
|
data/RELEASING.md
CHANGED
@@ -14,10 +14,7 @@ rake
|
|
14
14
|
|
15
15
|
Check that the last build succeeded in [Github Actions](https://github.com/mongoid/mongoid-scroll/actions) for all supported platforms.
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.4.1` to `0.4.2`).
|
20
|
-
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.4.1` to `0.5.0`).
|
17
|
+
Check that the version in [lib/mongoid/scroll/version.rb](lib/mongoid/scroll/version.rb) is the one you are releasing.
|
21
18
|
|
22
19
|
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
23
20
|
|
data/Rakefile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/gem_tasks'
|
3
3
|
|
4
|
-
require File.expand_path('
|
4
|
+
require File.expand_path('lib/mongoid/scroll/version', __dir__)
|
5
5
|
|
6
6
|
begin
|
7
7
|
Bundler.setup(:default, :development)
|
8
8
|
rescue Bundler::BundlerError => e
|
9
|
-
|
10
|
-
|
9
|
+
warn e.message
|
10
|
+
warn 'Run `bundle install` to install missing gems'
|
11
11
|
exit e.status_code
|
12
12
|
end
|
13
13
|
|
data/UPGRADING.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Upgrading
|
2
2
|
|
3
|
+
## Upgrading to >= 2.0.0
|
4
|
+
|
5
|
+
The second argument yielded in the block in `Mongoid::Criteria::Scrollable#scroll` and `Mongo::Scrollable#scroll` has changed from a cursor to an instance of `Mongoid::Criteria::Scrollable` which provides `next_cursor` and `previous_cursor`. The `next_cursor` method returns the same cursor as in versions prior to 2.0.0.
|
6
|
+
|
7
|
+
For example, this code:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
Feed::Item.asc(field_name).limit(2).scroll(cursor) do |_, next_cursor|
|
11
|
+
cursor = next_cursor
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
Should be updated to:
|
16
|
+
|
17
|
+
```
|
18
|
+
Feed::Item.asc(field_name).limit(2).scroll(cursor) do |_, iterator|
|
19
|
+
cursor = iterator.next_cursor
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
3
23
|
## Upgrading to >= 1.0.0
|
4
24
|
|
5
25
|
### Mismatched Sort Fields
|
@@ -9,6 +29,6 @@ Both `Mongoid::Criteria::Scrollable#scroll` and `Mongo::Scrollable` now raise a
|
|
9
29
|
For example, the following code will now raise a `MismatchedSortFieldsError` because we set a different field name (`position`) from the `created_at` field used to sort in `scroll`.
|
10
30
|
|
11
31
|
```ruby
|
12
|
-
cursor.field_name = "position"
|
32
|
+
cursor.field_name = "position"
|
13
33
|
Feed::Item.desc(:created_at).scroll(cursor)
|
14
34
|
```
|
@@ -5,7 +5,6 @@ require 'mongoid-scroll'
|
|
5
5
|
require 'faker'
|
6
6
|
|
7
7
|
Mongoid.logger.level = Logger::INFO
|
8
|
-
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
|
9
8
|
Mongoid.connect_to 'mongoid_scroll_demo'
|
10
9
|
Mongoid.purge!
|
11
10
|
|
@@ -24,7 +23,7 @@ total_items = 20
|
|
24
23
|
scroll_by = 7
|
25
24
|
|
26
25
|
# insert items with a position out-of-order
|
27
|
-
rands = (0..total_items).to_a.sort { rand }[0..total_items]
|
26
|
+
rands = (0..total_items).to_a.sort { |_l, _r| rand }[0..total_items]
|
28
27
|
total_items.times do |_i|
|
29
28
|
Feed::Item.create! title: Faker::Lorem.sentence, position: rands.pop
|
30
29
|
end
|
@@ -38,10 +37,11 @@ loop do
|
|
38
37
|
next_cursor = nil
|
39
38
|
Feed::Item.asc(:position).limit(scroll_by).scroll(current_cursor) do |item, cursor|
|
40
39
|
puts "#{item.position}: #{item.title}"
|
41
|
-
next_cursor = cursor
|
40
|
+
next_cursor = cursor.next_cursor
|
42
41
|
total_shown += 1
|
43
42
|
end
|
44
43
|
break unless next_cursor
|
44
|
+
|
45
45
|
# destroy an item just for the heck of it, scroll is not affected
|
46
46
|
Feed::Item.asc(:position).first.destroy
|
47
47
|
end
|
data/lib/config/locales/en.yml
CHANGED
@@ -27,4 +27,7 @@ en:
|
|
27
27
|
message: "Unsupported field type."
|
28
28
|
summary: "The type of the field '%{field}' is not supported: %{type}."
|
29
29
|
resolution: "Please open a feature request in https://github.com/mongoid/mongoid-scroll."
|
30
|
-
|
30
|
+
unsupported_type:
|
31
|
+
message: "Unsupported type."
|
32
|
+
summary: "The type supplied in the cursor is not supported: %{type}."
|
33
|
+
resolution: "The cursor type can be either ':previous' or ':next'."
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mongoid
|
2
|
+
class Criteria
|
3
|
+
module Scrollable
|
4
|
+
class Iterator
|
5
|
+
attr_accessor :previous_cursor, :current_cursor, :next_cursor
|
6
|
+
|
7
|
+
def initialize(previous_cursor:, current_cursor:, next_cursor:)
|
8
|
+
@previous_cursor = previous_cursor
|
9
|
+
@current_cursor = current_cursor
|
10
|
+
@next_cursor = next_cursor
|
11
|
+
end
|
12
|
+
|
13
|
+
def first_cursor
|
14
|
+
@first_cursor ||= next_cursor.class.new(nil, next_cursor.sort_options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|