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

Cleanup #272

Merged
merged 6 commits into from
Sep 17, 2023
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
15 changes: 8 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
ruby: [2.5, 2.6, 2.7, 3.0, jruby, truffleruby]
mongoid: [7]
ruby: [2.7, 3.0, 3.1, 3.2, truffleruby]
mongoid: [7, 8]
experimental: [false]
include:
- ruby: 2.7
mongoid: HEAD
experimental: true
- ruby: 3.0
- ruby: 3.2
mongoid: HEAD
experimental: true
- ruby: head
Expand All @@ -29,8 +27,11 @@ jobs:
- ruby: head
mongoid: HEAD
experimental: true
- ruby: jruby
mongoid: 8
experimental: true
- ruby: jruby-head
mongoid: 7
mongoid: 8
experimental: true
- ruby: truffleruby-head
mongoid: 7
Expand Down
20 changes: 19 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7
NewCops: enable
SuggestExtensions: false

Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Style/Documentation:
Enabled: false

Expand Down
40 changes: 1 addition & 39 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-08-11 17:20:10 UTC using RuboCop version 1.18.4.
# on 2023-09-17 18:58:11 UTC using RuboCop version 1.56.3.
# 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
Expand All @@ -13,41 +13,3 @@ Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/mongoid/slug_spec.rb'
- 'spec/tasks/mongoid_slug_rake_spec.rb'

# Offense count: 4
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 44

# Offense count: 24
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
Metrics/BlockLength:
Max: 525

# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 7
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 23

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 937

# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 11

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowOnConstant.
Style/CaseEquality:
Exclude:
- 'lib/mongoid/slug/unique_slug.rb'
203 changes: 106 additions & 97 deletions CHANGELOG.md

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Dangerfile

This file was deleted.

17 changes: 9 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ source 'https://rubygems.org'

gemspec name: 'mongoid-slug'

case version = ENV['MONGOID_VERSION'] || '7'
case (version = ENV['MONGOID_VERSION'] || '8')
when 'HEAD'
gem 'mongoid', github: 'mongodb/mongoid'
when /^7/
gem 'mongoid', '~> 7'
when /\A\d+\z/
gem 'mongoid', "~> #{version}.0"
else
gem 'mongoid', version
end

group :test do
gem 'mongoid-danger', '~> 0.1.0', require: false
gem 'rubocop', '~> 1.18.4'
gem 'rubocop-rspec'
end
gem 'rake'
gem 'rspec'
gem 'rspec-its'
gem 'rubocop'
gem 'rubocop-rspec'
gem 'uuid'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It sits idly on top of [stringex](https://github.com/rsl/stringex), supporting n

### Version Support

Mongoid Slug 7.x requires at least Mongoid 7.0.0 and Ruby 2.5.0. For earlier Mongoid and Ruby version support, please use an earlier version of Mongoid Slug.
Mongoid Slug 7.x requires at least Mongoid 7.0.0 and Ruby 2.7.0. For earlier Mongoid and Ruby version support, please use an earlier version of Mongoid Slug.

Mongoid Slug is compatible with all MongoDB versions which Mongoid supports, however, please see "Slug Max Length" section below for MongoDB 4.0 and earlier.

Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/slug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def apply_slug

# skip slug generation and use Mongoid id
# to find document instead
return true if new_slug.size.zero?
return true if new_slug.empty?

# avoid duplicate slugs
_slugs&.delete(new_slug)
Expand Down
8 changes: 3 additions & 5 deletions lib/mongoid/slug/unique_slug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ def initialize(slug, documents, pattern)
history_slugs = doc._slugs
next if history_slugs.nil?

existing_slugs.push(*history_slugs.find_all { |cur_slug| cur_slug =~ regexp_pattern })
existing_slugs.push(*history_slugs.grep(regexp_pattern))
last_entered_slug.push(*history_slugs.last) if history_slugs.last =~ regexp_pattern
existing_history_slugs.push(*history_slugs.first(history_slugs.length - 1).find_all do |cur_slug|
cur_slug =~ regexp_pattern
end)
existing_history_slugs.push(*history_slugs.first(history_slugs.length - 1).grep(regexp_pattern))
end
end

Expand Down Expand Up @@ -116,7 +114,7 @@ def find_unique(attempt = nil)
@state.include_slug unless model.class.look_like_slugs?([@_slug])

# make sure that the slug is not equal to a reserved word
@state.include_slug if slug_reserved_words.any? { |word| word === @_slug }
@state.include_slug if slug_reserved_words.any? { |word| word === @_slug } # rubocop:disable Style/CaseEquality

# only look for a new unique slug if the existing slugs contains the current slug
# - e.g if the slug 'foo-2' is taken, but 'foo' is available, the user can use 'foo'.
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/slug/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module Mongoid #:nodoc:
module Mongoid # :nodoc:
module Slug
VERSION = '7.0.0'
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/mongoid_slug.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace :mongoid_slug do
desc 'Goes though all documents and sets slug if not already set'
task set: :environment do |_, args|
::Rails.application.eager_load! if defined?(Rails)
Rails.application.eager_load! if defined?(Rails)
klasses = Mongoid::Config.models.find_all { |c| c.ancestors.include?(Mongoid::Slug) }
unless klasses.blank?
models = args.extras
Expand Down
8 changes: 2 additions & 6 deletions mongoid-slug.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ Gem::Specification.new do |s|
s.description = 'Mongoid URL slug or permalink generator'
s.license = 'MIT'

s.required_ruby_version = '>= 2.5'
s.required_ruby_version = '>= 2.7'

s.add_dependency 'mongoid', '>= 7.0'
s.add_dependency 'stringex', '~> 2.0'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rspec-its'
s.add_development_dependency 'uuid'

s.files = Dir.glob('lib/**/*') + %w[LICENSE README.md]
s.test_files = Dir.glob('spec/**/*')
s.require_paths = ['lib']
s.metadata['rubygems_mfa_required'] = 'true'
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def database_id
RSpec.configure do |c|
c.raise_errors_for_deprecations!

c.before :all do
c.before(:all) do
Mongoid.logger.level = Logger::INFO
Mongo::Logger.logger.level = Logger::INFO
end
Expand Down
Loading