Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded rubocop to 1.66.1. #46

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rake
- rubocop-rspec

AllCops:
NewCops: enable
Exclude:
- vendor/**/*
- gemfiles/vendor/**/*
185 changes: 152 additions & 33 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,159 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-03-09 01:14:57 +0100 using RuboCop version 0.49.1.
# on 2024-09-07 13:11:15 UTC using RuboCop version 1.66.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 5
# Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb
Bundler/DuplicatedGem:
# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'Gemfile'
- 'mongoid-scroll.gemspec'

# Offense count: 8
Metrics/AbcSize:
Max: 38
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/NonDeterministicRequireOrder:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 18
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 274
# Offense count: 7
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 28

# Offense count: 1
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 103
Max: 108

# Offense count: 5
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 13

# Offense count: 153
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 252

# Offense count: 7
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 23
Max: 24

# Offense count: 4
# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 12
Max: 13

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
# 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
Naming/FileName:
Exclude:
- 'Rakefile.rb'
- 'lib/mongoid-scroll.rb'

# Offense count: 3
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 34
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
- 'spec/mongoid/criteria_spec.rb'
- 'spec/mongoid/cursor_spec.rb'

# Offense count: 34
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
- 'spec/mongoid/cursor_spec.rb'

# Offense count: 17
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 18

# Offense count: 3
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
RSpec/IndexedLet:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 2
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 11
RSpec/MultipleExpectations:
Max: 4

# Offense count: 4
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 3
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4

# Offense count: 3
# Configuration parameters: AllowedPatterns.
# AllowedPatterns: ^expect_, ^assert_
RSpec/NoExpectationExample:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'

# Offense count: 4
RSpec/RepeatedDescription:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'

# Offense count: 4
RSpec/RepeatedExample:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'

# Offense count: 3
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
# Include: **/*_spec.rb
RSpec/SpecFilePathFormat:
Exclude:
- '**/spec/routing/**/*'
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
- 'spec/mongoid/cursor_spec.rb'
- 'spec/mongoid/scroll_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Rake/Desc:
Exclude:
- 'Rakefile'

# Offense count: 12
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'examples/feed.rb'
- 'lib/mongoid/criteria/scrollable.rb'
- 'lib/mongoid/criteria/scrollable/iterator.rb'
- 'lib/mongoid/scroll/base_cursor.rb'
- 'lib/mongoid/scroll/cursor.rb'
- 'lib/mongoid/scroll/errors/base.rb'
Expand All @@ -61,22 +162,40 @@ Style/Documentation:
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'
- 'lib/mongoid/scroll/errors/no_such_field_error.rb'
- 'lib/mongoid/scroll/errors/unsupported_field_type_error.rb'
- 'lib/mongoid/scroll/errors/unsupported_type_error.rb'

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# 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
Style/FileName:
Exclude:
- 'lib/mongoid-scroll.rb'
# Offense count: 34
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/MultilineTernaryOperator:
Exclude:
- 'lib/mongoid/scroll/cursor.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles.
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedCompactTypes.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
EnforcedStyle: compact

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'lib/mongoid/scroll/errors/mismatched_sort_fields_error.rb'
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'

# Offense count: 36
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 252
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [#43](https://github.com/mongoid/mongoid-scroll/pull/43): Add `current_cursor` - [@GCorbel](https://github.com/GCorbel).
* [#44](https://github.com/mongoid/mongoid-scroll/pull/44): Drop support for Mogoid 5 and Mongo Ruby Driver - [@dblock](https://github.com/dblock).
* [#45](https://github.com/mongoid/mongoid-scroll/pull/45): Add support for Mogoid 9 - [@dblock](https://github.com/dblock).
* [#46](https://github.com/mongoid/mongoid-scroll/pull/46): Upgrade RuboCop to 1.66.1 - [@dblock](https://github.com/dblock).
* Your contribution here.

### 1.0.1 (2023/03/15)
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ group :development, :test do
gem 'rake'
gem 'rspec', '~> 3.0'
gem 'rspec-its'
gem 'rubocop', '0.49.1'
gem 'rubocop', '1.66.1'
gem 'rubocop-rake'
gem 'rubocop-rspec'
end
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
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'rubygems'
require 'bundler/gem_tasks'

require File.expand_path('../lib/mongoid/scroll/version', __FILE__)
require File.expand_path('lib/mongoid/scroll/version', __dir__)

begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts 'Run `bundle install` to install missing gems'
warn e.message
warn 'Run `bundle install` to install missing gems'
exit e.status_code
end

Expand Down
5 changes: 3 additions & 2 deletions examples/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Item
scroll_by = 7

# insert items with a position out-of-order
rands = (0..total_items).to_a.sort { rand }[0..total_items]
rands = (0..total_items).to_a.sort { |_l, _r| rand }[0..total_items]
total_items.times do |_i|
Feed::Item.create! title: Faker::Lorem.sentence, position: rands.pop
end
Expand All @@ -38,10 +38,11 @@ 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

# destroy an item just for the heck of it, scroll is not affected
Feed::Item.asc(:position).first.destroy
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoid/criteria/scrollable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def scroll(cursor_or_type = nil, &_block)
criteria = dup
criteria.merge!(default_sort) if no_sort_option?
cursor_options = build_cursor_options(criteria)
cursor = cursor.is_a?(cursor_type) ? cursor : new_cursor(cursor_type, cursor, cursor_options)
cursor = new_cursor(cursor_type, cursor, cursor_options) unless cursor.is_a?(cursor_type)
raise_mismatched_sort_fields_error!(cursor, cursor_options) if different_sort_fields?(cursor, cursor_options)
records = find_records(criteria, cursor)
if block_given?
Expand Down Expand Up @@ -99,4 +99,4 @@ def scroll_field_type(criteria)
end
end

Mongoid::Criteria.send(:include, Mongoid::Criteria::Scrollable)
Mongoid::Criteria.include Mongoid::Criteria::Scrollable
8 changes: 4 additions & 4 deletions lib/mongoid/scroll/base64_encoded_cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ def initialize(value, options = {})
if value
begin
parsed = ::JSON.parse(::Base64.strict_decode64(value))
rescue
rescue StandardError
raise Mongoid::Scroll::Errors::InvalidBase64CursorError.new(cursor: value)
end
super parse_field_value(parsed['field_type'], parsed['field_name'], parsed['value']), {
super(parse_field_value(parsed['field_type'], parsed['field_name'], parsed['value']), {
field_type: parsed['field_type'],
field_name: parsed['field_name'],
direction: parsed['direction'],
include_current: parsed['include_current'],
tiebreak_id: parsed['tiebreak_id'] && !parsed['tiebreak_id'].empty? ? BSON::ObjectId.from_string(parsed['tiebreak_id']) : nil,
type: parsed['type'].try(:to_sym)
}
})
else
super nil, options
super(nil, options)
end
end

Expand Down
Loading
Loading