Skip to content

Commit

Permalink
Fix and run example in CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Sep 7, 2024
1 parent 1876d50 commit f1daf90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jobs:
bundler-cache: true
- name: Run tests
run: bundle exec rspec
- name: Run examples
run: bundle exec ruby examples/feed.rb
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ Mongoid extension that enables infinite scrolling for `Mongoid::Criteria` and `M

## Compatibility

This gem supports Mongoid 6, 7 and 8.
This gem supports Mongoid 6, 7, 8 and 9.

## Demo

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

There're also two code samples for Mongoid in [examples](examples). Run `bundle exec ruby examples/feed.rb`.
Take a look at [this example](examples/feed.rb). Try with with `bundle exec ruby examples/feed.rb`.

## The Problem

Expand All @@ -55,8 +53,10 @@ A sample model.
module Feed
class Item
include Mongoid::Document

field :title, type: String
field :position, type: Integer

index({ position: 1, _id: 1 })
end
end
Expand All @@ -73,7 +73,7 @@ Feed::Item.desc(:position).limit(5).scroll do |record, iterator|
end
```

Resume iterating using saved cursor and save the cursor to go backward.
Resume iterating using the saved cursor and save the cursor to go backwards.

```ruby
Feed::Item.desc(:position).limit(5).scroll(saved_iterator.next_cursor) do |record, iterator|
Expand Down
2 changes: 1 addition & 1 deletion examples/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Item
next_cursor = nil
Feed::Item.asc(:position).limit(scroll_by).scroll(current_cursor) do |item, cursor|
puts "#{item.position}: #{item.title}"
next_cursor = cursor
next_cursor = cursor.next_cursor
total_shown += 1
end
break unless next_cursor
Expand Down

0 comments on commit f1daf90

Please sign in to comment.