mongoid-scroll 1.0.1 → 2.0.1
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/.github/workflows/ci.yml +26 -7
- data/.github/workflows/danger-comment.yml +9 -0
- data/.github/workflows/danger.yml +9 -15
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +153 -35
- data/CHANGELOG.md +22 -5
- data/Dangerfile +5 -1
- data/Gemfile +16 -8
- data/README.md +27 -38
- data/RELEASING.md +31 -50
- data/Rakefile +3 -3
- data/UPGRADING.md +21 -1
- data/examples/{mongoid_scroll_feed.rb → feed.rb} +4 -3
- data/lib/config/locales/en.yml +4 -1
- data/lib/mongoid/criteria/scrollable/fields.rb +6 -0
- data/lib/mongoid/criteria/scrollable/iterator.rb +19 -0
- data/lib/mongoid/criteria/scrollable.rb +29 -9
- 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 +139 -37
- data/spec/mongoid/cursor_spec.rb +112 -63
- data/spec/mongoid/scroll_spec.rb +1 -1
- data/spec/spec_helper.rb +14 -3
- data/spec/support/feed/embedded_item.rb +2 -0
- data/spec/support/feed/item.rb +1 -1
- metadata +13 -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
data/RELEASING.md
CHANGED
|
@@ -1,67 +1,48 @@
|
|
|
1
|
-
Releasing Mongoid::Scroll
|
|
2
|
-
=========================
|
|
1
|
+
# Releasing Mongoid::Scroll
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
Use the upstream checkout on clean `master`, verify `origin` is `mongoid/mongoid-scroll`, and run `git pull --ff-only`. Follow semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
## Prepare
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Set `lib/mongoid/scroll/version.rb` to the release version, date its `CHANGELOG.md` section using `YYYY/MM/DD`, and remove the contribution placeholder.
|
|
9
8
|
|
|
10
|
-
```
|
|
9
|
+
```sh
|
|
11
10
|
bundle install
|
|
12
|
-
rake
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Check that the last build succeeded in [Github Actions](https://github.com/mongoid/mongoid-scroll/actions) for all supported platforms.
|
|
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`).
|
|
21
|
-
|
|
22
|
-
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
### 0.4.0 (2018/12/24)
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Remove the line with "* Your contribution here.", since there will be no more contributions to this release.
|
|
29
|
-
|
|
30
|
-
Commit your changes.
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
git add CHANGELOG.md lib/mongoid-scroll/version.rb
|
|
34
|
-
git commit -m "Preparing for release, 0.4.0."
|
|
11
|
+
bundle exec rake
|
|
12
|
+
git add CHANGELOG.md lib/mongoid/scroll/version.rb RELEASING.md
|
|
13
|
+
git commit -m "Preparing for release, 2.0.1."
|
|
35
14
|
git push origin master
|
|
36
15
|
```
|
|
37
16
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
$ rake release
|
|
17
|
+
## Publish RubyGems and GitHub
|
|
42
18
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Pushed git commits and tags.
|
|
46
|
-
Pushed mongoid-scroll 0.4.0 to rubygems.org.
|
|
19
|
+
```sh
|
|
20
|
+
bundle exec rake release
|
|
47
21
|
```
|
|
48
22
|
|
|
49
|
-
|
|
23
|
+
The task builds the gem, pushes its tag, and publishes to RubyGems. Complete MFA when prompted. If interrupted, inspect the tag and RubyGems version before retrying; never move a published tag. If only publication is missing, resume with `gem push pkg/mongoid-scroll-2.0.1.gem`.
|
|
50
24
|
|
|
51
|
-
|
|
25
|
+
A tag is not a GitHub release. After confirming RubyGems publication, create the matching GitHub release with changelog notes:
|
|
52
26
|
|
|
27
|
+
```sh
|
|
28
|
+
version=2.0.1
|
|
29
|
+
notes="$(mktemp)"
|
|
30
|
+
awk -v version="$version" '
|
|
31
|
+
/^### / {
|
|
32
|
+
if (found) exit
|
|
33
|
+
if ($2 == version) found = 1
|
|
34
|
+
next
|
|
35
|
+
}
|
|
36
|
+
found { print }
|
|
37
|
+
' CHANGELOG.md > "$notes"
|
|
38
|
+
gh release create "v$version" --repo mongoid/mongoid-scroll --verify-tag --title "$version" --notes-file "$notes" --latest
|
|
39
|
+
rm "$notes"
|
|
40
|
+
curl --fail --silent --show-error "https://rubygems.org/api/v2/rubygems/mongoid-scroll/versions/$version.json"
|
|
41
|
+
gh release view "v$version" --repo mongoid/mongoid-scroll
|
|
53
42
|
```
|
|
54
|
-
### 0.4.1 (Next)
|
|
55
43
|
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Increment the minor version, modify [lib/mongoid-scroll/version.rb](lib/mongoid-scroll/version.rb).
|
|
44
|
+
Verify both the published gem and non-draft GitHub release before declaring completion.
|
|
60
45
|
|
|
61
|
-
|
|
46
|
+
## Prepare the Next Version
|
|
62
47
|
|
|
63
|
-
|
|
64
|
-
git add CHANGELOG.md lib/mongoid-scroll/version.rb
|
|
65
|
-
git commit -m "Preparing for next release, 0.4.1."
|
|
66
|
-
git push origin master
|
|
67
|
-
```
|
|
48
|
+
Increment the development patch version in `lib/mongoid/scroll/version.rb` (for example, `2.0.2`). Add `### 2.0.2 (Next)` with a contribution placeholder above the released changelog section. Commit and push those changes to `master`, leaving the released tag unchanged.
|
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
|
```
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require 'bundler'
|
|
2
2
|
Bundler.setup(:default, :development)
|
|
3
3
|
|
|
4
|
+
require 'logger'
|
|
4
5
|
require 'mongoid-scroll'
|
|
5
6
|
require 'faker'
|
|
6
7
|
|
|
7
8
|
Mongoid.logger.level = Logger::INFO
|
|
8
|
-
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
|
|
9
9
|
Mongoid.connect_to 'mongoid_scroll_demo'
|
|
10
10
|
Mongoid.purge!
|
|
11
11
|
|
|
@@ -24,7 +24,7 @@ total_items = 20
|
|
|
24
24
|
scroll_by = 7
|
|
25
25
|
|
|
26
26
|
# insert items with a position out-of-order
|
|
27
|
-
rands = (0..total_items).to_a.sort { rand }[0..total_items]
|
|
27
|
+
rands = (0..total_items).to_a.sort { |_l, _r| rand }[0..total_items]
|
|
28
28
|
total_items.times do |_i|
|
|
29
29
|
Feed::Item.create! title: Faker::Lorem.sentence, position: rands.pop
|
|
30
30
|
end
|
|
@@ -38,10 +38,11 @@ loop do
|
|
|
38
38
|
next_cursor = nil
|
|
39
39
|
Feed::Item.asc(:position).limit(scroll_by).scroll(current_cursor) do |item, cursor|
|
|
40
40
|
puts "#{item.position}: #{item.title}"
|
|
41
|
-
next_cursor = cursor
|
|
41
|
+
next_cursor = cursor.next_cursor
|
|
42
42
|
total_shown += 1
|
|
43
43
|
end
|
|
44
44
|
break unless next_cursor
|
|
45
|
+
|
|
45
46
|
# destroy an item just for the heck of it, scroll is not affected
|
|
46
47
|
Feed::Item.asc(:position).first.destroy
|
|
47
48
|
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'."
|
|
@@ -5,12 +5,18 @@ module Mongoid
|
|
|
5
5
|
module Fields
|
|
6
6
|
private
|
|
7
7
|
|
|
8
|
+
def scroll_model_field(field_name)
|
|
9
|
+
klass.fields[field_name.to_s] ||
|
|
10
|
+
raise(Mongoid::Scroll::Errors::NoSuchFieldError.new(field: field_name))
|
|
11
|
+
end
|
|
12
|
+
|
|
8
13
|
def raise_mismatched_sort_fields_error!(cursor, criteria_cursor_options)
|
|
9
14
|
diff = cursor.sort_options.reject { |k, v| criteria_cursor_options[k] == v }
|
|
10
15
|
raise Mongoid::Scroll::Errors::MismatchedSortFieldsError.new(diff: diff)
|
|
11
16
|
end
|
|
12
17
|
|
|
13
18
|
def different_sort_fields?(cursor, criteria_cursor_options)
|
|
19
|
+
scroll_model_field(cursor.field_name)
|
|
14
20
|
criteria_cursor_options[:field_type] = criteria_cursor_options[:field_type].to_s
|
|
15
21
|
criteria_cursor_options[:field_name] = criteria_cursor_options[:field_name].to_s
|
|
16
22
|
criteria_cursor_options != cursor.sort_options
|
|
@@ -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
|
|
@@ -10,15 +10,24 @@ module Mongoid
|
|
|
10
10
|
criteria = dup
|
|
11
11
|
criteria.merge!(default_sort) if no_sort_option?
|
|
12
12
|
cursor_options = build_cursor_options(criteria)
|
|
13
|
-
cursor =
|
|
13
|
+
cursor = new_cursor(cursor_type, cursor, cursor_options) unless cursor.is_a?(cursor_type)
|
|
14
14
|
raise_mismatched_sort_fields_error!(cursor, cursor_options) if different_sort_fields?(cursor, cursor_options)
|
|
15
|
-
|
|
15
|
+
records = find_records(criteria, cursor)
|
|
16
16
|
if block_given?
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
previous_cursor = nil
|
|
18
|
+
current_cursor = nil
|
|
19
|
+
records.each do |record|
|
|
20
|
+
previous_cursor ||= cursor_from_record(cursor_type, record, cursor_options.merge(type: :previous))
|
|
21
|
+
current_cursor ||= cursor_from_record(cursor_type, record, cursor_options.merge(include_current: true))
|
|
22
|
+
iterator = Mongoid::Criteria::Scrollable::Iterator.new(
|
|
23
|
+
previous_cursor: previous_cursor,
|
|
24
|
+
next_cursor: cursor_from_record(cursor_type, record, cursor_options),
|
|
25
|
+
current_cursor: current_cursor
|
|
26
|
+
)
|
|
27
|
+
yield record, iterator
|
|
19
28
|
end
|
|
20
29
|
else
|
|
21
|
-
|
|
30
|
+
records
|
|
22
31
|
end
|
|
23
32
|
end
|
|
24
33
|
|
|
@@ -60,10 +69,21 @@ module Mongoid
|
|
|
60
69
|
cursor_type.new(cursor, cursor_options)
|
|
61
70
|
end
|
|
62
71
|
|
|
63
|
-
def
|
|
72
|
+
def find_records(criteria, cursor)
|
|
64
73
|
cursor_criteria = criteria.dup
|
|
65
74
|
cursor_criteria.selector = { '$and' => [criteria.selector, cursor.criteria] }
|
|
66
|
-
|
|
75
|
+
if cursor.type == :previous
|
|
76
|
+
pipeline = [
|
|
77
|
+
{ '$match' => cursor_criteria.selector },
|
|
78
|
+
{ '$sort' => { cursor.field_name => -cursor.direction } },
|
|
79
|
+
{ '$limit' => criteria.options[:limit] },
|
|
80
|
+
{ '$sort' => { cursor.field_name => cursor.direction } }
|
|
81
|
+
]
|
|
82
|
+
aggregation = cursor_criteria.view.aggregate(pipeline)
|
|
83
|
+
aggregation.map { |record| Mongoid::Factory.from_db(cursor_criteria.klass, record) }
|
|
84
|
+
else
|
|
85
|
+
cursor_criteria.order_by(_id: scroll_direction(criteria))
|
|
86
|
+
end
|
|
67
87
|
end
|
|
68
88
|
|
|
69
89
|
def cursor_from_record(cursor_type, record, cursor_options)
|
|
@@ -72,11 +92,11 @@ module Mongoid
|
|
|
72
92
|
|
|
73
93
|
def scroll_field_type(criteria)
|
|
74
94
|
scroll_field = scroll_field(criteria)
|
|
75
|
-
field =
|
|
95
|
+
field = scroll_model_field(scroll_field)
|
|
76
96
|
field.foreign_key? && field.object_id_field? ? BSON::ObjectId : field.type
|
|
77
97
|
end
|
|
78
98
|
end
|
|
79
99
|
end
|
|
80
100
|
end
|
|
81
101
|
|
|
82
|
-
Mongoid::Criteria.
|
|
102
|
+
Mongoid::Criteria.include Mongoid::Criteria::Scrollable
|
|
@@ -10,18 +10,19 @@ module Mongoid
|
|
|
10
10
|
if value
|
|
11
11
|
begin
|
|
12
12
|
parsed = ::JSON.parse(::Base64.strict_decode64(value))
|
|
13
|
-
rescue
|
|
13
|
+
rescue StandardError
|
|
14
14
|
raise Mongoid::Scroll::Errors::InvalidBase64CursorError.new(cursor: value)
|
|
15
15
|
end
|
|
16
|
-
super
|
|
16
|
+
super(parse_field_value(parsed['field_type'], parsed['field_name'], parsed['value']), {
|
|
17
17
|
field_type: parsed['field_type'],
|
|
18
18
|
field_name: parsed['field_name'],
|
|
19
19
|
direction: parsed['direction'],
|
|
20
20
|
include_current: parsed['include_current'],
|
|
21
|
-
tiebreak_id: parsed['tiebreak_id'] && !parsed['tiebreak_id'].empty? ? BSON::ObjectId.from_string(parsed['tiebreak_id']) : nil
|
|
22
|
-
|
|
21
|
+
tiebreak_id: parsed['tiebreak_id'] && !parsed['tiebreak_id'].empty? ? BSON::ObjectId.from_string(parsed['tiebreak_id']) : nil,
|
|
22
|
+
type: parsed['type'].try(:to_sym)
|
|
23
|
+
})
|
|
23
24
|
else
|
|
24
|
-
super
|
|
25
|
+
super(nil, options)
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
@@ -32,7 +33,8 @@ module Mongoid
|
|
|
32
33
|
field_name: field_name,
|
|
33
34
|
direction: direction,
|
|
34
35
|
include_current: include_current,
|
|
35
|
-
tiebreak_id: tiebreak_id && tiebreak_id.to_s
|
|
36
|
+
tiebreak_id: tiebreak_id && tiebreak_id.to_s,
|
|
37
|
+
type: type
|
|
36
38
|
}.to_json)
|
|
37
39
|
end
|
|
38
40
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Mongoid
|
|
2
2
|
module Scroll
|
|
3
3
|
class BaseCursor
|
|
4
|
-
attr_accessor :value, :tiebreak_id, :field_type, :field_name, :direction, :include_current
|
|
4
|
+
attr_accessor :value, :tiebreak_id, :field_type, :field_name, :direction, :include_current, :type
|
|
5
5
|
|
|
6
6
|
def initialize(value, options = {})
|
|
7
7
|
@value = value
|
|
@@ -10,17 +10,16 @@ module Mongoid
|
|
|
10
10
|
@field_name = options[:field_name]
|
|
11
11
|
@direction = options[:direction] || 1
|
|
12
12
|
@include_current = options[:include_current] || false
|
|
13
|
+
@type = options[:type] || :next
|
|
14
|
+
|
|
15
|
+
raise Mongoid::Scroll::Errors::UnsupportedTypeError.new(type: @type) unless %i[previous next].include?(@type)
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def criteria
|
|
16
19
|
mongo_value = value.class.mongoize(value) if value
|
|
17
20
|
cursor_criteria = { field_name => { compare_direction => mongo_value } } if mongo_value
|
|
18
21
|
tiebreak_criteria = { field_name => mongo_value, :_id => { tiebreak_compare_direction => tiebreak_id } } if mongo_value && tiebreak_id
|
|
19
|
-
cursor_selector =
|
|
20
|
-
Mongoid::Criteria::Queryable::Selector.new
|
|
21
|
-
else
|
|
22
|
-
Origin::Selector.new
|
|
23
|
-
end
|
|
22
|
+
cursor_selector = Mongoid::Criteria::Queryable::Selector.new
|
|
24
23
|
cursor_selector['$or'] = [cursor_criteria, tiebreak_criteria].compact if cursor_criteria || tiebreak_criteria
|
|
25
24
|
cursor_selector.__evolve_object_id__
|
|
26
25
|
end
|
|
@@ -69,8 +68,7 @@ module Mongoid
|
|
|
69
68
|
return nil unless value
|
|
70
69
|
|
|
71
70
|
case field_type.to_s
|
|
72
|
-
when 'BSON::ObjectId' then value.to_s
|
|
73
|
-
when 'String' then value.to_s
|
|
71
|
+
when 'BSON::ObjectId', 'String' then value.to_s
|
|
74
72
|
when 'Date' then Time.utc(value.year, value.month, value.day).to_i
|
|
75
73
|
when 'DateTime', 'Time' then value.utc.to_f.round(3)
|
|
76
74
|
when 'Float' then value.to_f
|
|
@@ -86,20 +84,23 @@ module Mongoid
|
|
|
86
84
|
field_type: field_type.to_s,
|
|
87
85
|
field_name: field_name.to_s,
|
|
88
86
|
direction: options[:direction] || 1,
|
|
89
|
-
include_current: options[:include_current] || false
|
|
87
|
+
include_current: options[:include_current] || false,
|
|
88
|
+
type: options[:type].try(:to_sym) || :next
|
|
90
89
|
}
|
|
91
90
|
elsif options && (field = options[:field])
|
|
92
91
|
{
|
|
93
92
|
field_type: field.type.to_s,
|
|
94
93
|
field_name: field.name.to_s,
|
|
95
94
|
direction: options[:direction] || 1,
|
|
96
|
-
include_current: options[:include_current] || false
|
|
95
|
+
include_current: options[:include_current] || false,
|
|
96
|
+
type: options[:type].try(:to_sym) || :next
|
|
97
97
|
}
|
|
98
98
|
end
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
def compare_direction
|
|
102
|
-
|
|
102
|
+
dir = type == :previous ? -direction : direction
|
|
103
|
+
dir == 1 ? '$gt' : '$lt'
|
|
103
104
|
end
|
|
104
105
|
|
|
105
106
|
def tiebreak_compare_direction
|
|
@@ -4,20 +4,20 @@ module Mongoid
|
|
|
4
4
|
def initialize(value = nil, options = {})
|
|
5
5
|
options = extract_field_options(options)
|
|
6
6
|
raise ArgumentError.new 'Missing options[:field_name] and/or options[:field_type].' unless options
|
|
7
|
+
|
|
7
8
|
if value
|
|
8
9
|
parts = value.split(':') if value
|
|
9
|
-
unless parts && parts.length >= 2
|
|
10
|
-
|
|
11
|
-
end
|
|
10
|
+
raise Mongoid::Scroll::Errors::InvalidCursorError.new(cursor: value) unless parts && parts.length >= 2
|
|
11
|
+
|
|
12
12
|
value = parse_field_value(
|
|
13
13
|
options[:field_type],
|
|
14
14
|
options[:field_name],
|
|
15
15
|
parts[0...-1].join(':')
|
|
16
16
|
)
|
|
17
17
|
options[:tiebreak_id] = BSON::ObjectId.from_string(parts[-1])
|
|
18
|
-
super
|
|
18
|
+
super
|
|
19
19
|
else
|
|
20
|
-
super
|
|
20
|
+
super(nil, options)
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -21,13 +21,13 @@ module Mongoid
|
|
|
21
21
|
@resolution = create_resolution(key, attributes)
|
|
22
22
|
|
|
23
23
|
"\nProblem:\n #{@problem}" \
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
"\nSummary:\n #{@summary}" \
|
|
25
|
+
"\nResolution:\n #{@resolution}"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
private
|
|
29
29
|
|
|
30
|
-
BASE_KEY = 'mongoid.scroll.errors.messages'.freeze
|
|
30
|
+
BASE_KEY = 'mongoid.scroll.errors.messages'.freeze # :nodoc:
|
|
31
31
|
|
|
32
32
|
# Given the key of the specific error and the options hash, translate the
|
|
33
33
|
# message.
|
|
@@ -38,7 +38,7 @@ module Mongoid
|
|
|
38
38
|
#
|
|
39
39
|
# Returns a localized error message string.
|
|
40
40
|
def translate(key, options)
|
|
41
|
-
::I18n.translate("#{BASE_KEY}.#{key}",
|
|
41
|
+
::I18n.translate("#{BASE_KEY}.#{key}", locale: :en, **options).strip
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
# Create the problem.
|
|
@@ -4,9 +4,7 @@ module Mongoid
|
|
|
4
4
|
# Raised when the original sort params and the cursor sort params are different
|
|
5
5
|
class MismatchedSortFieldsError < Mongoid::Scroll::Errors::Base
|
|
6
6
|
def initialize(opts = {})
|
|
7
|
-
if opts[:diff] && opts[:diff].is_a?(Hash)
|
|
8
|
-
opts = opts.merge(diff: opts[:diff].keys.join(', '))
|
|
9
|
-
end
|
|
7
|
+
opts = opts.merge(diff: opts[:diff].keys.join(', ')) if opts[:diff] && opts[:diff].is_a?(Hash)
|
|
10
8
|
super(compose_message('mismatched_sort_fields', opts))
|
|
11
9
|
end
|
|
12
10
|
end
|
|
@@ -3,9 +3,7 @@ module Mongoid
|
|
|
3
3
|
module Errors
|
|
4
4
|
class MultipleSortFieldsError < Mongoid::Scroll::Errors::Base
|
|
5
5
|
def initialize(opts = {})
|
|
6
|
-
if opts[:sort] && opts[:sort].is_a?(Hash)
|
|
7
|
-
opts = opts.merge(sort: opts[:sort].keys.join(', '))
|
|
8
|
-
end
|
|
6
|
+
opts = opts.merge(sort: opts[:sort].keys.join(', ')) if opts[:sort] && opts[:sort].is_a?(Hash)
|
|
9
7
|
super(compose_message('multiple_sort_fields', opts))
|
|
10
8
|
end
|
|
11
9
|
end
|
|
@@ -6,3 +6,4 @@ require 'mongoid/scroll/errors/invalid_cursor_error'
|
|
|
6
6
|
require 'mongoid/scroll/errors/invalid_base64_cursor_error'
|
|
7
7
|
require 'mongoid/scroll/errors/no_such_field_error'
|
|
8
8
|
require 'mongoid/scroll/errors/unsupported_field_type_error'
|
|
9
|
+
require 'mongoid/scroll/errors/unsupported_type_error'
|
data/lib/mongoid-scroll.rb
CHANGED
|
@@ -3,7 +3,6 @@ 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'
|
|
7
6
|
require 'mongoid/scroll/version'
|
|
8
7
|
require 'mongoid/scroll/errors'
|
|
9
8
|
require 'mongoid/scroll/base_cursor'
|
|
@@ -11,5 +10,5 @@ require 'mongoid/scroll/cursor'
|
|
|
11
10
|
require 'mongoid/scroll/base64_encoded_cursor'
|
|
12
11
|
require 'mongoid/criteria/scrollable/fields'
|
|
13
12
|
require 'mongoid/criteria/scrollable/cursors'
|
|
14
|
-
require '
|
|
13
|
+
require 'mongoid/criteria/scrollable/iterator'
|
|
15
14
|
require 'mongoid/criteria/scrollable'
|
data/mongoid-scroll.gemspec
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
$LOAD_PATH.push File.expand_path('
|
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
|
2
2
|
require 'mongoid/scroll/version'
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
s.homepage = 'http://github.com/mongoid/mongoid-scroll'
|
|
14
14
|
s.licenses = ['MIT']
|
|
15
15
|
s.summary = 'Mongoid extensions to enable infinite scroll.'
|
|
16
|
-
s.add_dependency 'mongoid', '>= 3.0'
|
|
17
|
-
s.add_dependency 'mongoid-compatibility'
|
|
18
16
|
s.add_dependency 'i18n'
|
|
17
|
+
s.add_dependency 'mongoid', '>= 6.0'
|
|
18
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
|
19
19
|
end
|