Skip to content

Commit

Permalink
Merge branch 'master' into remove-default-id
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields authored Sep 8, 2023
2 parents 8bcc3c3 + 5891734 commit 903ea95
Show file tree
Hide file tree
Showing 54 changed files with 482 additions and 279 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI RSpec Test

on: [push, pull_request]

jobs:
build:
name: >-
${{ matrix.ruby }}
env:
CI: true
TESTOPTS: -v
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
ruby: [2.5, 2.6, 2.7, 3.0, jruby, truffleruby]
mongoid: [7]
experimental: [false]
include:
- ruby: 2.7
mongoid: HEAD
experimental: true
- ruby: 3.0
mongoid: HEAD
experimental: true
- ruby: head
mongoid: 7
experimental: true
- ruby: head
mongoid: HEAD
experimental: true
- ruby: jruby-head
mongoid: 7
experimental: true
- ruby: truffleruby-head
mongoid: 7
experimental: true

steps:
- name: repo checkout
uses: actions/checkout@v2

- name: start mongodb
uses: supercharge/[email protected]
with:
mongodb-version: 4.4
mongodb-replica-set: rs0

- name: load ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler: 2

- name: bundle install
run: bundle install --jobs 4 --retry 3
env:
MONGOID_VERSION: ${{ matrix.mongoid }}

- name: rubocop
timeout-minutes: 5
run: bundle exec rubocop
continue-on-error: ${{ matrix.experimental }}
env:
MONGOID_VERSION: ${{ matrix.mongoid }}

- name: test
timeout-minutes: 10
run: bundle exec rake spec
continue-on-error: ${{ matrix.experimental }}
env:
MONGOID_VERSION: ${{ matrix.mongoid }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.*
.idea
pkg
Gemfile.lock
20 changes: 17 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
inherit_from: .rubocop_todo.yml

AllCops:
Exclude:
- vendor/**/*
TargetRubyVersion: 2.5
NewCops: enable
SuggestExtensions: false

Style/Documentation:
Enabled: false

inherit_from: .rubocop_todo.yml
Style/DoubleNegation:
Enabled: false

Style/ModuleFunction:
EnforcedStyle: extend_self

Style/OptionalBooleanParameter:
Enabled: false

Style/Semicolon:
Exclude:
- 'spec/**/*.rb'
68 changes: 24 additions & 44 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,53 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-08-16 08:14:07 -0400 using RuboCop version 0.58.2.
# on 2021-08-11 17:20:10 UTC using RuboCop version 1.18.4.
# 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: 6
# Configuration parameters: Include.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/DuplicatedGem:
# Offense count: 5
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'Gemfile'
- 'spec/mongoid/slug_spec.rb'
- 'spec/tasks/mongoid_slug_rake_spec.rb'

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

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

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

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

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

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

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: braces, no_braces, context_dependent
Style/BracesAroundHashParameters:
Exclude:
- 'lib/mongoid/slug/criteria.rb'

# Offense count: 1
# Configuration parameters: AllowOnConstant.
Style/CaseEquality:
Exclude:
- 'lib/mongoid/slug/unique_slug.rb'

# Offense count: 1
Style/DoubleNegation:
Exclude:
- 'lib/mongoid/slug.rb'

# Offense count: 9
# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 151
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 138
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## 6.0.1 (Next)
## 7.0.0 (Next)

* Your contribution here.
* [#268](https://github.com/mongoid/mongoid-slug/pull/268): Ensure localized slugs index expected localized slug fields - [@johnnyshields](https://github.com/johnnyshields).

## 6.0.1 (2021/08/12)

* [#266](https://github.com/mongoid/mongoid-slug/pull/266): Ensure localized slugs index expected localized slug fields - [@onomated](https://github.com/onomated), [@johnnyshields](https://github.com/johnnyshields).
* [#265](https://github.com/mongoid/mongoid-slug/pull/265): Add Github Actions and remove Travis CI - [@johnnyshields](https://github.com/kailan).
* [#255](https://github.com/mongoid/mongoid-slug/pull/255): Use mongoid::config#models in rake task, resolves #247 - [@kailan](https://github.com/kailan).

## 6.0.0 (2018/09/17)
Expand Down
2 changes: 2 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

danger.import_dangerfile(gem: 'mongoid-danger')
13 changes: 4 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec name: 'mongoid-slug'
Expand All @@ -7,19 +9,12 @@ when 'HEAD'
gem 'mongoid', github: 'mongodb/mongoid'
when /^7/
gem 'mongoid', '~> 7'
when /^6/
gem 'mongoid', '~> 6'
when /^5/
gem 'mongoid', '~> 5'
when /^4/
gem 'mongoid', '~> 4'
when /^3/
gem 'mongoid', '~> 3'
else
gem 'mongoid', version
end

group :test do
gem 'mongoid-danger', '~> 0.1.0', require: false
gem 'rubocop', '0.58.2'
gem 'rubocop', '~> 1.18.4'
gem 'rubocop-rspec'
end
6 changes: 0 additions & 6 deletions Guardfile

This file was deleted.

51 changes: 45 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
Mongoid Slug
============

Mongoid Slug generates a URL slug or permalink based on one or more fields in a Mongoid model. It sits idly on top of [stringex](https://github.com/rsl/stringex), supporting non-Latin characters.
Mongoid Slug generates a URL slug or permalink based on one or more fields in a Mongoid model.
It sits idly on top of [stringex](https://github.com/rsl/stringex), supporting non-Latin characters.

[![Build Status](https://secure.travis-ci.org/mongoid/mongoid-slug.svg)](http://travis-ci.org/mongoid/mongoid-slug)
[![Build Status](https://github.com/mongoid/mongoid-slug/actions/workflows/test.yml/badge.svg?query=branch%3Amaster)](https://github.com/mongoid/mongoid-slug/actions/workflows/test.ym?query=branch%3Amaster)
[![Gem Version](https://badge.fury.io/rb/mongoid-slug.svg)](http://badge.fury.io/rb/mongoid-slug)
[![Code Climate](https://codeclimate.com/github/mongoid/mongoid-slug.svg)](https://codeclimate.com/github/mongoid/mongoid-slug)

### 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 is compatible with all MongoDB versions which Mongoid supports, however, please see "Slug Max Length" section below for MongoDB 4.0 and earlier.

### Installation

Add to your Gemfile:
Expand Down Expand Up @@ -46,6 +53,7 @@ Mongoid Slug will attempt to determine whether you want to find using the `slugs
```ruby
Book.fields['_id'].type
=> String

book = Book.find 'a-thousand-plateaus' # Finds by slugs
=> ...

Expand All @@ -61,8 +69,10 @@ end

Post.fields['_id'].type
=> String

post = Post.find 'a-thousand-plateaus' # Finds by slugs
=> ...

post = Post.find '50b1386a0482939864000001' # Finds by bson ids
=> ...
```
Expand Down Expand Up @@ -165,9 +175,16 @@ class Employee
end
```

### Limit Slug Length
### Slug Max Length

MongoDB has a default limit around 1KB to the size of the index keys and will raise error 17280, `key too large to index` when trying to create a record that causes an index key to exceed that limit. By default slugs are of the form `text[-number]` and the text portion is limited in size to `Mongoid::Slug::MONGO_INDEX_KEY_LIMIT_BYTES - 32` bytes. You can change this limit with `max_length` or set it to `nil` if you're running MongoDB with [failIndexKeyTooLong](https://docs.mongodb.org/manual/reference/parameters/#param.failIndexKeyTooLong) set to `false`.
MongoDB [featureCompatibilityVersion](https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv)
"4.0" and earlier applies an [Index Key Limit](https://docs.mongodb.com/manual/reference/limits/#mongodb-limit-Index-Key-Limit)
which limits the total size of an index entry to around 1KB and will raise error,
`17280 - key too large to index` when trying to create a record that causes an index key to exceed that limit.
By default slugs are of the form `text[-number]` and the text portion is limited in size
to `Mongoid::Slug::MONGO_INDEX_KEY_LIMIT_BYTES - 32` bytes.
You can change this limit with `max_length` or set it to `nil` if you're running MongoDB
with [failIndexKeyTooLong](https://docs.mongodb.org/manual/reference/parameters/#param.failIndexKeyTooLong) set to `false`.

```ruby
class Company
Expand Down Expand Up @@ -271,7 +288,8 @@ Specifying an array of custom reserved words will overwrite these defaults.

### Localize Slugs

The slugs can be localized:
The slugs can be localized. This feature is built upon Mongoid localized fields,
so fallbacks and localization works as documented in the Mongoid manual.

```ruby
class PageSlugLocalize
Expand All @@ -283,7 +301,28 @@ class PageSlugLocalize
end
```

This feature is built upon Mongoid localized fields, so fallbacks and localization works as documented in the Mongoid manual.
By specifying `localize: true`, the slug index will be created on the
[I18n.default_locale](http://guides.rubyonrails.org/i18n.html#the-public-i18n-api) field only.
For example, if `I18n.default_locale` is `:en`, the index will be generated as follows:

```ruby
slug :title, localize: true

# The following index is auto-generated:
index({ '_slugs.en' => 1 }, { unique: true, sparse: true })
```

If you are supporting multiple locales, you may specify the list of locales on which
to create indexes as an `Array`.

```ruby
slug :title, localize: [:fr, :es, :de]

# The following indexes are auto-generated:
index({ '_slugs.fr' => 1 }, { unique: true, sparse: true })
index({ '_slugs.es' => 1 }, { unique: true, sparse: true })
index({ '_slugs.de' => 1 }, { unique: true, sparse: true })
```

### Custom Find Strategies

Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler'
require 'rspec/core/rake_task'

Expand Down
Loading

0 comments on commit 903ea95

Please sign in to comment.