mongoid-scroll 1.0.1 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26aa74f5571582e25321e096612b63056c8ac9839299434ee2007ba778042421
4
- data.tar.gz: 95b7d7739e45b8a38b15ff74af68be5f25bc8c346dd291c0f062d14c46439c71
3
+ metadata.gz: 6408a43ccf6d68cedb7f2cfa984be3f3e66cf63f29c79eaaa506a8eb671da84b
4
+ data.tar.gz: 44b25144b153ef375a1425b61e1a431b10c8eaa71293c246d13d550bdfe168ca
5
5
  SHA512:
6
- metadata.gz: 886b6450b7aa4d0d0ee768ba59752464ba8e3743649990e99349bc03540c1715ba10ecbe845cfaa9a27a9e7082d3d205e99ae1d6651bd8f3a403ba02615bbee7
7
- data.tar.gz: f16fad09019d31f73d436352efd83fb7278a716d61d25c055ceae678c8cd3bfec2815e408861ff578039c6f20fcba230a0e1695522bcf523acf06d269317ddb8
6
+ metadata.gz: ebab5c9fd5bf4de86d4e5c8305b67dea439842c57b335d9934a29c611029683cccaa8b059ffefeb7e308c832b6a8fc54de399dc828075c157b7c94aacdd48143
7
+ data.tar.gz: c187f3dfb04d7908c7332b1bec0d0a0c535125fcd232161faf8f17da65e121bd9b5168e7a703c25894d0495411737f6c6ea470bb8279f51f1d4d385b1e8728be
@@ -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
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ coverage
data/.rubocop.yml CHANGED
@@ -1,6 +1,11 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ require:
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+
3
7
  AllCops:
8
+ NewCops: enable
4
9
  Exclude:
5
10
  - vendor/**/*
6
11
  - gemfiles/vendor/**/*
data/.rubocop_todo.yml CHANGED
@@ -1,59 +1,159 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-03-09 01:14:57 +0100 using RuboCop version 0.49.1.
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: 5
10
- # Configuration parameters: Include.
11
- # Include: **/Gemfile, **/gems.rb
12
- Bundler/DuplicatedGem:
9
+ # Offense count: 1
10
+ # Configuration parameters: Severity, Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
13
  Exclude:
14
- - 'Gemfile'
14
+ - 'mongoid-scroll.gemspec'
15
15
 
16
- # Offense count: 8
17
- Metrics/AbcSize:
18
- Max: 38
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: 18
21
- # Configuration parameters: CountComments, ExcludedMethods.
22
- Metrics/BlockLength:
23
- Max: 274
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: 103
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: 23
40
+ Max: 24
44
41
 
45
- # Offense count: 4
42
+ # Offense count: 3
43
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
46
44
  Metrics/PerceivedComplexity:
47
- Max: 12
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/mongoid_scroll_feed.rb'
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: 1
67
- # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
68
- # 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
69
- Style/FileName:
70
- Exclude:
71
- - 'lib/mongoid-scroll.rb'
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
- # Cop supports --auto-correct.
80
- # Configuration parameters: SupportedStyles.
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): Removed support for Mongoid 3, 4 and Moped - [@dblock](https://github.com/dblock).
13
- * [#34](https://github.com/mongoid/mongoid-scroll/pull/34): Added support for Mongoid 8 - [@dblock](https://github.com/dblock).
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): Added Danger, PR linter - [@dblock](https://github.com/dblock).
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
- * Implemeneted Rubocop, Ruby linter - [@dblock](https://github.com/dblock).
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
- * Extended `Moped::Query` with `scroll` - [@dblock](https://github.com/dblock).
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', '0.49.1'
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
- [![Dependency Status](https://gemnasium.com/mongoid/mongoid-scroll.svg)](https://gemnasium.com/mongoid/mongoid-scroll)
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 5, 6, 7 and 8.
25
+ This gem supports Mongoid 6, 7, 8 and 9.
28
26
 
29
27
  ## Demo
30
28
 
31
- Check out [shows on artsy.net](http://artsy.net/shows). Keep scrolling down.
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
- saved_cursor = nil
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
- Resume iterating using the previously saved cursor.
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
- saved_cursor = next_cursor
72
+ saved_iterator = iterator
85
73
  end
86
74
  ```
87
75
 
88
- The iteration finishes when no more records are available. You can also finish iterating over the remaining records by omitting the query limit.
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(saved_cursor) do |record, next_cursor|
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
- ### Mongo-Ruby-Driver (Mongoid 5)
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
- saved_cursor = nil
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
- saved_cursor = next_cursor
90
+ saved_iterator = iterator
105
91
  end
106
92
  ```
107
93
 
108
- Resume iterating using the previously saved cursor.
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
- session[:feed_items].find.sort(position: -1).limit(5).scroll(saved_cursor, { field_type: DateTime }) do |record, next_cursor|
99
+ Feed::Item.desc(:position).limit(5).scroll(saved_iterator.next_cursor) do |record, iterator|
112
100
  # each record, one-by-one
113
- saved_cursor = next_cursor
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 previous iteration and unlike MongoDB cursors will not expire.
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, next_cursor|
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-2023 [Daniel Doubrovkine](http://github.com/dblock), based on code by [Frank Macreery](http://github.com/macreery), [Artsy Inc.](http://artsy.net)
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
- Increment the version, modify [lib/mongoid/scroll/version.rb](lib/mongoid/scroll/version.rb).
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('../lib/mongoid/scroll/version', __FILE__)
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
- $stderr.puts e.message
10
- $stderr.puts 'Run `bundle install` to install missing gems'
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
@@ -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