Skip to content

Commit 6704e52

Browse files
committed
Removed support for Moped and fixed specs.
1 parent 8a7a433 commit 6704e52

25 files changed

+278
-499
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ jobs:
77
strategy:
88
matrix:
99
entry:
10-
- { ruby: '2.6', mongodb: '4.4', mongoid: '3' }
11-
- { ruby: '2.6', mongodb: '4.4', mongoid: '4' }
1210
- { ruby: '2.6', mongodb: '4.4', mongoid: '5' }
1311
- { ruby: '2.7', mongodb: '4.4', mongoid: '6' }
1412
- { ruby: '2.7', mongodb: '4.4', mongoid: '7' }

.rubocop_todo.yml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-03-05 15:22:11 -0500 using RuboCop version 0.49.1.
3+
# on 2023-03-05 20:26:55 -0500 using RuboCop version 0.49.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -13,37 +13,45 @@ Bundler/DuplicatedGem:
1313
Exclude:
1414
- 'Gemfile'
1515

16+
# Offense count: 1
17+
# Cop supports --auto-correct.
18+
# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect.
19+
# SupportedStylesAlignWith: keyword, variable, start_of_line
20+
Lint/EndAlignment:
21+
Exclude:
22+
- 'lib/mongoid/scroll/errors/invalid_base64_cursor_error.rb'
23+
1624
# Offense count: 1
1725
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
1826
Lint/UselessAccessModifier:
1927
Exclude:
2028
- 'lib/mongoid/scroll/cursor.rb'
2129

22-
# Offense count: 6
30+
# Offense count: 7
2331
Metrics/AbcSize:
24-
Max: 69
32+
Max: 38
2533

26-
# Offense count: 17
34+
# Offense count: 15
2735
# Configuration parameters: CountComments, ExcludedMethods.
2836
Metrics/BlockLength:
29-
Max: 255
37+
Max: 252
3038

31-
# Offense count: 7
39+
# Offense count: 5
3240
Metrics/CyclomaticComplexity:
3341
Max: 11
3442

35-
# Offense count: 163
43+
# Offense count: 127
3644
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
3745
# URISchemes: http, https
3846
Metrics/LineLength:
3947
Max: 222
4048

41-
# Offense count: 7
49+
# Offense count: 6
4250
# Configuration parameters: CountComments.
4351
Metrics/MethodLength:
44-
Max: 26
52+
Max: 23
4553

46-
# Offense count: 5
54+
# Offense count: 3
4755
Metrics/PerceivedComplexity:
4856
Max: 12
4957

@@ -52,17 +60,17 @@ Style/Documentation:
5260
Exclude:
5361
- 'spec/**/*'
5462
- 'test/**/*'
55-
- 'examples/mongoid_scroll_feed.rb'
63+
- 'examples/scroll_feed.rb'
5664
- 'lib/mongo/scrollable.rb'
5765
- 'lib/mongoid/criteria/scrollable.rb'
5866
- 'lib/mongoid/scroll/base_cursor.rb'
5967
- 'lib/mongoid/scroll/cursor.rb'
6068
- 'lib/mongoid/scroll/errors/base.rb'
69+
- 'lib/mongoid/scroll/errors/invalid_base64_cursor_error.rb'
6170
- 'lib/mongoid/scroll/errors/invalid_cursor_error.rb'
6271
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'
6372
- 'lib/mongoid/scroll/errors/no_such_field_error.rb'
6473
- 'lib/mongoid/scroll/errors/unsupported_field_type_error.rb'
65-
- 'lib/moped/scrollable.rb'
6674

6775
# Offense count: 1
6876
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
@@ -71,12 +79,6 @@ Style/FileName:
7179
Exclude:
7280
- 'lib/mongoid-scroll.rb'
7381

74-
# Offense count: 1
75-
# Configuration parameters: MinBodyLength.
76-
Style/GuardClause:
77-
Exclude:
78-
- 'lib/moped/scrollable.rb'
79-
8082
# Offense count: 1
8183
Style/MultilineTernaryOperator:
8284
Exclude:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [#29](https://github.com/mongoid/mongoid-scroll/pull/29): Add ability to include the current record to the cursor - [@FabienChaynes](https://github.com/FabienChaynes).
66
* [#30](https://github.com/mongoid/mongoid-scroll/pull/30): Prevent discrepancy between the original sort and the cursor sort - [@FabienChaynes](https://github.com/FabienChaynes).
77
* [#32](https://github.com/mongoid/mongoid-scroll/pull/32): Add Base64 serialization for cursors - [@FabienChaynes](https://github.com/FabienChaynes).
8+
* [#33](https://github.com/mongoid/mongoid-scroll/pull/33): Removed support for Mongoid 3, 4 and Moped - [@dblock](https://github.com/dblock).
89
* Your contribution here.
910

1011
### 0.3.7 (2021/06/01)

README.md

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1+
- [Mongoid::Scroll](#mongoidscroll)
2+
- [Compatibility](#compatibility)
3+
- [Demo](#demo)
4+
- [The Problem](#the-problem)
5+
- [Installation](#installation)
6+
- [Usage](#usage)
7+
- [Mongoid](#mongoid)
8+
- [Mongo-Ruby-Driver (Mongoid 5)](#mongo-ruby-driver-mongoid-5)
9+
- [Indexes and Performance](#indexes-and-performance)
10+
- [Cursors](#cursors)
11+
- [Standard Cursor](#standard-cursor)
12+
- [Base64 Encoded Cursor](#base64-encoded-cursor)
13+
- [Contributing](#contributing)
14+
- [Copyright and License](#copyright-and-license)
15+
116
# Mongoid::Scroll
217

318
[![Gem Version](https://badge.fury.io/rb/mongoid-scroll.svg)](https://badge.fury.io/rb/mongoid-scroll)
419
[![Build Status](https://github.com/mongoid/mongoid-scroll/actions/workflows/ci.yml/badge.svg)](https://github.com/mongoid/mongoid-scroll/actions/workflows/ci.yml)
520
[![Dependency Status](https://gemnasium.com/mongoid/mongoid-scroll.svg)](https://gemnasium.com/mongoid/mongoid-scroll)
621
[![Code Climate](https://codeclimate.com/github/mongoid/mongoid-scroll.svg)](https://codeclimate.com/github/mongoid/mongoid-scroll)
722

8-
Mongoid extension that enables infinite scrolling for `Mongoid::Criteria`, `Moped::Query` and `Mongo::Collection::View`.
23+
Mongoid extension that enables infinite scrolling for `Mongoid::Criteria` and `Mongo::Collection::View`.
924

1025
## Compatibility
1126

12-
This gem supports Mongoid 3, 4, 5, 6, 7, Moped and Mongo-Ruby-Driver.
27+
This gem supports Mongoid 5, 6, and 7.
1328

1429
## Demo
1530

1631
Check out [shows on artsy.net](http://artsy.net/shows). Keep scrolling down.
1732

18-
There're also two code samples for Mongoid and Moped in [examples](examples). Run `bundle exec ruby examples/mongoid_scroll_feed.rb`.
33+
There're also two code samples for Mongoid in [examples](examples). Run `bundle exec ruby examples/mongoid_scroll_feed.rb`.
1934

2035
## The Problem
2136

@@ -78,27 +93,6 @@ Feed::Item.desc(:position).scroll(saved_cursor) do |record, next_cursor|
7893
end
7994
```
8095

81-
### Moped (Mongoid 3 and 4)
82-
83-
Scroll a `Moped::Query` and save a cursor to the last item. You must also supply a `field_type` of the sort criteria.
84-
85-
```ruby
86-
saved_cursor = nil
87-
session[:feed_items].find.sort(position: -1).limit(5).scroll(nil, { field_type: DateTime }) do |record, next_cursor|
88-
# each record, one-by-one
89-
saved_cursor = next_cursor
90-
end
91-
```
92-
93-
Resume iterating using the previously saved cursor.
94-
95-
```ruby
96-
session[:feed_items].find.sort(position: -1).limit(5).scroll(saved_cursor, { field_type: DateTime }) do |record, next_cursor|
97-
# each record, one-by-one
98-
saved_cursor = next_cursor
99-
end
100-
```
101-
10296
### Mongo-Ruby-Driver (Mongoid 5)
10397

10498
Scroll a `Mongo::Collection::View` and save a cursor to the last item. You must also supply a `field_type` of the sort criteria.
@@ -183,11 +177,13 @@ cursor = Mongoid::Scroll::Cursor.from_record(record, { field_type: DateTime, fie
183177
Feed::Item.desc(:created_at).scroll(cursor) # Raises a Mongoid::Scroll::Errors::MismatchedSortFieldsError
184178
```
185179

186-
### Cursor Encoding
180+
### Standard Cursor
181+
182+
The `Mongoid::Scroll::Base64EncodedCursor` 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.
187183

188-
#### Base64
184+
### Base64 Encoded Cursor
189185

190-
`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.
186+
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.
191187

192188
```ruby
193189
Feed::Item.desc(:position).limit(5).scroll(Mongoid::Scroll::Base64EncodedCursor) do |record, next_cursor|

UPGRADING.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44

55
### Mismatched Sort Fields
66

7-
`Mongoid::Criteria::Scrollable#scroll`, `Moped::Scrollable` and `Mongo::Scrollable` now raise a `Mongoid::Scroll::Errors::MismatchedSortFieldsError` when there are discrepancies between the cursor sort options and the original sort options.
8-
Make sure to avoid this case or to handle the new exception.
7+
Both `Mongoid::Criteria::Scrollable#scroll` and `Mongo::Scrollable` now raise a `Mongoid::Scroll::Errors::MismatchedSortFieldsError` when there are discrepancies between the cursor sort options and the original sort options.
98

10-
```ruby
11-
cursor.field_name = "position" # Avoid this, it'll raise because on the following line the sort is by created_at
12-
Feed::Item.desc(:created_at).scroll(cursor)
13-
```
9+
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`.
1410

1511
```ruby
16-
begin
17-
Feed::Item.desc(:created_at).scroll(cursor)
18-
rescue Mongoid::Scroll::Errors::MismatchedSortFieldsError
19-
# If cursor can be modified externally, handle the exception
20-
end
12+
cursor.field_name = "position"
13+
Feed::Item.desc(:created_at).scroll(cursor)
2114
```

examples/mongoid_scroll_feed.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44
require 'mongoid-scroll'
55
require 'faker'
66

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+
Mongoid.logger.level = Logger::INFO
8+
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
159
Mongoid.connect_to 'mongoid_scroll_demo'
1610
Mongoid.purge!
1711

examples/moped_scroll_feed.rb

Lines changed: 0 additions & 45 deletions
This file was deleted.

lib/config/locales/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ en:
1515
message: "The cursor supplied is invalid."
1616
summary: "The cursor supplied is invalid: %{cursor}."
1717
resolution: "Cursors must be in the form 'value:tiebreak_id'."
18+
invalid_base64_cursor:
19+
message: "The cursor supplied is invalid."
20+
summary: "The cursor supplied is invalid: %{cursor}."
21+
resolution: "Cursors must be a base64-encoded string."
1822
no_such_field:
1923
message: "Invalid field."
2024
summary: "The field supplied in the cursor does not exist: %{field}."

lib/mongo/scrollable.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module Mongo
22
module Scrollable
33
include Mongoid::Criteria::Scrollable::Fields
4+
include Mongoid::Criteria::Scrollable::Cursors
45

5-
def scroll(cursor = nil, options = nil, &_block)
6+
def scroll(cursor_or_type = nil, options = nil, &_block)
7+
cursor, cursor_type = cursor_and_type(cursor_or_type)
68
view = self
79
# we don't support scrolling over a view with multiple fields
810
raise Mongoid::Scroll::Errors::MultipleSortFieldsError.new(sort: view.sort) if view.sort && view.sort.keys.size != 1
@@ -12,7 +14,7 @@ def scroll(cursor = nil, options = nil, &_block)
1214
# scroll cursor from the parameter, with value and tiebreak_id
1315
options = { field_type: BSON::ObjectId } unless options
1416
cursor_options = { field_name: scroll_field, direction: scroll_direction }.merge(options)
15-
cursor = cursor.is_a?(Mongoid::Scroll::Cursor) ? cursor : Mongoid::Scroll::Cursor.new(cursor, cursor_options)
17+
cursor = cursor && cursor.is_a?(cursor_type) ? cursor : cursor_type.new(cursor, cursor_options)
1618
raise_mismatched_sort_fields_error!(cursor, cursor_options) if different_sort_fields?(cursor, cursor_options)
1719
# make a view
1820
view = Mongo::Collection::View.new(
@@ -25,7 +27,7 @@ def scroll(cursor = nil, options = nil, &_block)
2527
# scroll
2628
if block_given?
2729
view.each do |record|
28-
yield record, Mongoid::Scroll::Cursor.from_record(record, cursor_options)
30+
yield record, cursor_type.from_record(record, cursor_options)
2931
end
3032
else
3133
view

lib/mongoid-scroll.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
require 'mongoid/scroll/cursor'
1111
require 'mongoid/scroll/base64_encoded_cursor'
1212
require 'mongoid/criteria/scrollable/fields'
13-
require 'moped/scrollable' if Object.const_defined?(:Moped)
13+
require 'mongoid/criteria/scrollable/cursors'
1414
require 'mongo/scrollable' if Object.const_defined?(:Mongo)
1515
require 'mongoid/criteria/scrollable'

0 commit comments

Comments
 (0)