friendly_id 5.6.0 → 5.7.0
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/lib/friendly_id/version.rb +1 -1
- metadata +2 -44
- data/.gemtest +0 -0
- data/.github/FUNDING.yml +0 -1
- data/.github/dependabot.yml +0 -6
- data/.github/stale.yml +0 -17
- data/.github/workflows/release.yml +0 -29
- data/.github/workflows/test.yml +0 -86
- data/.gitignore +0 -14
- data/.yardopts +0 -8
- data/CONTRIBUTING.md +0 -11
- data/Gemfile +0 -23
- data/Rakefile +0 -100
- data/UPGRADING.md +0 -115
- data/bench.rb +0 -84
- data/friendly_id.gemspec +0 -31
- data/gemfiles/Gemfile.rails-6.0.rb +0 -22
- data/gemfiles/Gemfile.rails-6.1.rb +0 -22
- data/gemfiles/Gemfile.rails-7.0.rb +0 -22
- data/gemfiles/Gemfile.rails-7.1.rb +0 -22
- data/gemfiles/Gemfile.rails-7.2.rb +0 -22
- data/gemfiles/Gemfile.rails-8.0.rb +0 -22
- data/guide.rb +0 -24
- data/test/base_test.rb +0 -69
- data/test/benchmarks/finders.rb +0 -90
- data/test/benchmarks/object_utils.rb +0 -56
- data/test/candidates_test.rb +0 -142
- data/test/configuration_test.rb +0 -60
- data/test/core_test.rb +0 -35
- data/test/databases.yml +0 -22
- data/test/finders_test.rb +0 -76
- data/test/generator_test.rb +0 -38
- data/test/helper.rb +0 -125
- data/test/history_test.rb +0 -434
- data/test/numeric_slug_test.rb +0 -100
- data/test/object_utils_test.rb +0 -27
- data/test/reserved_test.rb +0 -73
- data/test/schema.rb +0 -117
- data/test/scoped_test.rb +0 -95
- data/test/sequentially_slugged_test.rb +0 -214
- data/test/shared.rb +0 -181
- data/test/simple_i18n_test.rb +0 -144
- data/test/slugged_test.rb +0 -628
- data/test/sti_test.rb +0 -135
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8a1f043f2634ba82853c8748c13dacf573cf7de6f99c71ede338d9aecd7f424
|
|
4
|
+
data.tar.gz: '033259395dcc4b75e595c4a81aedf839815768805c8f3d8bc8a2f1cb51df85ed'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cea6b61fc184a6d8f2c4468282440a7a4499a1af7ff3bb979c3c1659aa401d1459cb5e345e6dd1d56225304a5278b7b93625e619352975735b49385b295ca73f
|
|
7
|
+
data.tar.gz: fe4b2086cfebce9204cc349c8d0a1b31756fee02da072f2babfb56f87697d1a034be7a568ae78b9ccaf360cc8cf4509c59b9ccac68193dfe52859bb7ed018954
|
data/lib/friendly_id/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: friendly_id
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Norman Clarke
|
|
@@ -146,30 +146,9 @@ executables: []
|
|
|
146
146
|
extensions: []
|
|
147
147
|
extra_rdoc_files: []
|
|
148
148
|
files:
|
|
149
|
-
- ".gemtest"
|
|
150
|
-
- ".github/FUNDING.yml"
|
|
151
|
-
- ".github/dependabot.yml"
|
|
152
|
-
- ".github/stale.yml"
|
|
153
|
-
- ".github/workflows/release.yml"
|
|
154
|
-
- ".github/workflows/test.yml"
|
|
155
|
-
- ".gitignore"
|
|
156
|
-
- ".yardopts"
|
|
157
|
-
- CONTRIBUTING.md
|
|
158
149
|
- Changelog.md
|
|
159
|
-
- Gemfile
|
|
160
150
|
- MIT-LICENSE
|
|
161
151
|
- README.md
|
|
162
|
-
- Rakefile
|
|
163
|
-
- UPGRADING.md
|
|
164
|
-
- bench.rb
|
|
165
|
-
- friendly_id.gemspec
|
|
166
|
-
- gemfiles/Gemfile.rails-6.0.rb
|
|
167
|
-
- gemfiles/Gemfile.rails-6.1.rb
|
|
168
|
-
- gemfiles/Gemfile.rails-7.0.rb
|
|
169
|
-
- gemfiles/Gemfile.rails-7.1.rb
|
|
170
|
-
- gemfiles/Gemfile.rails-7.2.rb
|
|
171
|
-
- gemfiles/Gemfile.rails-8.0.rb
|
|
172
|
-
- guide.rb
|
|
173
152
|
- lib/friendly_id.rb
|
|
174
153
|
- lib/friendly_id/.gitattributes
|
|
175
154
|
- lib/friendly_id/base.rb
|
|
@@ -191,27 +170,6 @@ files:
|
|
|
191
170
|
- lib/friendly_id/slugged.rb
|
|
192
171
|
- lib/friendly_id/version.rb
|
|
193
172
|
- lib/generators/friendly_id_generator.rb
|
|
194
|
-
- test/base_test.rb
|
|
195
|
-
- test/benchmarks/finders.rb
|
|
196
|
-
- test/benchmarks/object_utils.rb
|
|
197
|
-
- test/candidates_test.rb
|
|
198
|
-
- test/configuration_test.rb
|
|
199
|
-
- test/core_test.rb
|
|
200
|
-
- test/databases.yml
|
|
201
|
-
- test/finders_test.rb
|
|
202
|
-
- test/generator_test.rb
|
|
203
|
-
- test/helper.rb
|
|
204
|
-
- test/history_test.rb
|
|
205
|
-
- test/numeric_slug_test.rb
|
|
206
|
-
- test/object_utils_test.rb
|
|
207
|
-
- test/reserved_test.rb
|
|
208
|
-
- test/schema.rb
|
|
209
|
-
- test/scoped_test.rb
|
|
210
|
-
- test/sequentially_slugged_test.rb
|
|
211
|
-
- test/shared.rb
|
|
212
|
-
- test/simple_i18n_test.rb
|
|
213
|
-
- test/slugged_test.rb
|
|
214
|
-
- test/sti_test.rb
|
|
215
173
|
homepage: https://github.com/norman/friendly_id
|
|
216
174
|
licenses:
|
|
217
175
|
- MIT
|
|
@@ -230,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
230
188
|
- !ruby/object:Gem::Version
|
|
231
189
|
version: '0'
|
|
232
190
|
requirements: []
|
|
233
|
-
rubygems_version:
|
|
191
|
+
rubygems_version: 4.0.6
|
|
234
192
|
specification_version: 4
|
|
235
193
|
summary: A comprehensive slugging and pretty-URL plugin.
|
|
236
194
|
test_files: []
|
data/.gemtest
DELETED
|
File without changes
|
data/.github/FUNDING.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
github: parndt
|
data/.github/dependabot.yml
DELETED
data/.github/stale.yml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Number of days of inactivity before an issue becomes stale
|
|
2
|
-
daysUntilStale: 84
|
|
3
|
-
# Number of days of inactivity before a stale issue is closed
|
|
4
|
-
daysUntilClose: 7
|
|
5
|
-
# Issues with these labels will never be considered stale
|
|
6
|
-
exemptLabels:
|
|
7
|
-
- pinned
|
|
8
|
-
- security
|
|
9
|
-
# Label to use when marking an issue as stale
|
|
10
|
-
staleLabel: stale
|
|
11
|
-
# Comment to post when marking an issue as stale. Set to `false` to disable
|
|
12
|
-
markComment: >
|
|
13
|
-
This issue has been automatically marked as stale because it has not had
|
|
14
|
-
recent activity. It will be closed if no further activity occurs. Thank you
|
|
15
|
-
for your contributions.
|
|
16
|
-
# Comment to post when closing a stale issue. Set to `false` to disable
|
|
17
|
-
closeComment: false
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
name: Release to rubygems.org
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
tags:
|
|
6
|
-
- 'v*.*.*'
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
push:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
|
|
12
|
-
permissions:
|
|
13
|
-
contents: write
|
|
14
|
-
id-token: write
|
|
15
|
-
|
|
16
|
-
environment: release
|
|
17
|
-
|
|
18
|
-
steps:
|
|
19
|
-
- uses: actions/checkout@v6
|
|
20
|
-
with:
|
|
21
|
-
persist-credentials: false
|
|
22
|
-
|
|
23
|
-
- name: Set up Ruby
|
|
24
|
-
uses: ruby/setup-ruby@v1
|
|
25
|
-
with:
|
|
26
|
-
bundler-cache: true
|
|
27
|
-
ruby-version: ruby
|
|
28
|
-
|
|
29
|
-
- uses: rubygems/release-gem@v1
|
data/.github/workflows/test.yml
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- 'master'
|
|
7
|
-
pull_request:
|
|
8
|
-
jobs:
|
|
9
|
-
test:
|
|
10
|
-
strategy:
|
|
11
|
-
matrix:
|
|
12
|
-
database: [ mysql, postgresql ]
|
|
13
|
-
gemfile: [ '8.0', '7.2', '7.1', '7.0', '6.1', '6.0' ]
|
|
14
|
-
ruby: [ '2.7', '3.0', '3.1', '3.2', '3.3', '3.4' ]
|
|
15
|
-
exclude:
|
|
16
|
-
- gemfile: '6.0'
|
|
17
|
-
ruby: '3.2'
|
|
18
|
-
- gemfile: '6.0'
|
|
19
|
-
ruby: '3.3'
|
|
20
|
-
- gemfile: '6.0'
|
|
21
|
-
ruby: '3.4'
|
|
22
|
-
- gemfile: '6.1'
|
|
23
|
-
ruby: '3.2'
|
|
24
|
-
- gemfile: '6.1'
|
|
25
|
-
ruby: '3.3'
|
|
26
|
-
- gemfile: '6.1'
|
|
27
|
-
ruby: '3.4'
|
|
28
|
-
- gemfile: '7.0'
|
|
29
|
-
ruby: '3.3'
|
|
30
|
-
- gemfile: '7.0'
|
|
31
|
-
ruby: '3.4'
|
|
32
|
-
- gemfile: '7.1'
|
|
33
|
-
ruby: '3.3'
|
|
34
|
-
- gemfile: '7.1'
|
|
35
|
-
ruby: '3.4'
|
|
36
|
-
- gemfile: '7.2'
|
|
37
|
-
ruby: '2.7'
|
|
38
|
-
- gemfile: '7.2'
|
|
39
|
-
ruby: '3.0'
|
|
40
|
-
- gemfile: '8.0'
|
|
41
|
-
ruby: '2.7'
|
|
42
|
-
- gemfile: '8.0'
|
|
43
|
-
ruby: '3.0'
|
|
44
|
-
- gemfile: '8.0'
|
|
45
|
-
ruby: '3.1'
|
|
46
|
-
fail-fast: false
|
|
47
|
-
runs-on: ubuntu-latest
|
|
48
|
-
|
|
49
|
-
env:
|
|
50
|
-
BUNDLE_GEMFILE: gemfiles/Gemfile.rails-${{ matrix.gemfile }}.rb
|
|
51
|
-
CI: true
|
|
52
|
-
COVERALLS: true
|
|
53
|
-
DB: ${{ matrix.database }}
|
|
54
|
-
MYSQL_PASSWORD: root
|
|
55
|
-
PGHOST: localhost
|
|
56
|
-
PGPASSWORD: runner
|
|
57
|
-
PGUSER: runner
|
|
58
|
-
RAILS_ENV: test
|
|
59
|
-
|
|
60
|
-
name: ${{ matrix.ruby }} ${{ matrix.database }} rails-${{ matrix.gemfile }}
|
|
61
|
-
steps:
|
|
62
|
-
- uses: actions/checkout@v6
|
|
63
|
-
|
|
64
|
-
- run: sudo apt-get update && sudo apt-get install libsqlite3-dev -y
|
|
65
|
-
|
|
66
|
-
- name: "Set up MySQL using VM's server"
|
|
67
|
-
if: ${{ env.DB == 'mysql' }}
|
|
68
|
-
run: |
|
|
69
|
-
sudo apt-get install libmysqlclient-dev -y
|
|
70
|
-
sudo systemctl start mysql.service
|
|
71
|
-
|
|
72
|
-
- name: "Set up PostgreSQL using VM's server"
|
|
73
|
-
if: ${{ env.DB == 'postgresql' }}
|
|
74
|
-
run: |
|
|
75
|
-
sudo apt-get install libpq-dev -y
|
|
76
|
-
sudo systemctl start postgresql.service
|
|
77
|
-
sudo -u postgres psql -c "CREATE USER runner WITH SUPERUSER PASSWORD 'runner'"
|
|
78
|
-
sudo -u postgres createdb runner
|
|
79
|
-
|
|
80
|
-
- uses: ruby/setup-ruby@v1
|
|
81
|
-
with:
|
|
82
|
-
bundler-cache: true
|
|
83
|
-
ruby-version: ${{ matrix.ruby }}
|
|
84
|
-
|
|
85
|
-
- run: bundle exec rake db:{create,up}
|
|
86
|
-
- run: bundle exec rake test
|
data/.gitignore
DELETED
data/.yardopts
DELETED
data/CONTRIBUTING.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# FriendlyId
|
|
2
|
-
|
|
3
|
-
Please ask questions on [Stack
|
|
4
|
-
Overflow](http://stackoverflow.com/questions/tagged/friendly-id) using the
|
|
5
|
-
"friendly_id" or "friendly-id" tag. Prior to asking, search and see if your
|
|
6
|
-
question has already been answered.
|
|
7
|
-
|
|
8
|
-
Please only post issues in Github issues for actual bugs.
|
|
9
|
-
|
|
10
|
-
I am asking people to do this because the same questions keep getting asked
|
|
11
|
-
over and over and over again in the issues.
|
data/Gemfile
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
source "https://rubygems.org"
|
|
2
|
-
|
|
3
|
-
gemspec
|
|
4
|
-
|
|
5
|
-
gem "standard"
|
|
6
|
-
gem "rake"
|
|
7
|
-
|
|
8
|
-
group :development, :test do
|
|
9
|
-
platforms :ruby do
|
|
10
|
-
gem "byebug"
|
|
11
|
-
gem "pry"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
platforms :jruby do
|
|
15
|
-
gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.beta2"
|
|
16
|
-
gem "kramdown"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
platforms :ruby, :rbx do
|
|
20
|
-
gem "sqlite3"
|
|
21
|
-
gem "redcarpet"
|
|
22
|
-
end
|
|
23
|
-
end
|
data/Rakefile
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
require "rubygems"
|
|
2
|
-
require "bundler/gem_tasks"
|
|
3
|
-
require "rake/testtask"
|
|
4
|
-
|
|
5
|
-
task default: :test
|
|
6
|
-
|
|
7
|
-
task :load_path do
|
|
8
|
-
%w[lib test].each do |path|
|
|
9
|
-
$LOAD_PATH.unshift(File.expand_path("../#{path}", __FILE__))
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
Rake::TestTask.new do |t|
|
|
14
|
-
t.libs << "test"
|
|
15
|
-
t.test_files = FileList["test/*_test.rb"]
|
|
16
|
-
t.verbose = true
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
desc "Remove temporary files"
|
|
20
|
-
task :clean do
|
|
21
|
-
`rm -rf *.gem doc pkg coverage`
|
|
22
|
-
%x(rm -f `find . -name '*.rbc'`)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
desc "Build YARD documentation"
|
|
26
|
-
task :yard do
|
|
27
|
-
puts `bundle exec yard`
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
desc "Run benchmarks"
|
|
31
|
-
task bench: :load_path do
|
|
32
|
-
require File.expand_path("../bench", __FILE__)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
desc "Run benchmarks on finders"
|
|
36
|
-
task bench_finders: :load_path do
|
|
37
|
-
require File.expand_path("../test/benchmarks/finders", __FILE__)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
desc "Run benchmarks on ObjectUtils"
|
|
41
|
-
task bench_object_utils: :load_path do
|
|
42
|
-
require File.expand_path("../test/benchmarks/object_utils", __FILE__)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
desc "Generate Guide.md"
|
|
46
|
-
task :guide do
|
|
47
|
-
load File.expand_path("../guide.rb", __FILE__)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
namespace :test do
|
|
51
|
-
desc "Run each test class in a separate process"
|
|
52
|
-
task :isolated do
|
|
53
|
-
dir = File.expand_path("../test", __FILE__)
|
|
54
|
-
Dir["#{dir}/*_test.rb"].each do |test|
|
|
55
|
-
puts "Running #{test}:"
|
|
56
|
-
puts `ruby -Ilib -Itest #{test}`
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
namespace :db do
|
|
62
|
-
desc "Create the database"
|
|
63
|
-
task create: :load_path do
|
|
64
|
-
require "helper"
|
|
65
|
-
driver = FriendlyId::Test::Database.driver
|
|
66
|
-
config = FriendlyId::Test::Database.config[driver]
|
|
67
|
-
commands = {
|
|
68
|
-
"mysql" => "mysql -h #{config["host"]} -P #{config["port"]} -u #{config["username"]} --password=#{config["password"]} -e 'create database #{config["database"]};' >/dev/null",
|
|
69
|
-
"postgres" => "psql -c 'create database #{config["database"]};' -U #{config["username"]} >/dev/null"
|
|
70
|
-
}
|
|
71
|
-
`#{commands[driver] || true}`
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
desc "Drop the database"
|
|
75
|
-
task drop: :load_path do
|
|
76
|
-
require "helper"
|
|
77
|
-
driver = FriendlyId::Test::Database.driver
|
|
78
|
-
config = FriendlyId::Test::Database.config[driver]
|
|
79
|
-
commands = {
|
|
80
|
-
"mysql" => "mysql -h #{config["host"]} -P #{config["port"]} -u #{config["username"]} --password=#{config["password"]} -e 'drop database #{config["database"]};' >/dev/null",
|
|
81
|
-
"postgres" => "psql -c 'drop database #{config["database"]};' -U #{config["username"]} >/dev/null"
|
|
82
|
-
}
|
|
83
|
-
`#{commands[driver] || true}`
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
desc "Set up the database schema"
|
|
87
|
-
task up: :load_path do
|
|
88
|
-
require "helper"
|
|
89
|
-
FriendlyId::Test::Schema.up
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
desc "Drop and recreate the database schema"
|
|
93
|
-
task reset: [:drop, :create]
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
task doc: :yard
|
|
97
|
-
|
|
98
|
-
task :docs do
|
|
99
|
-
sh %(git checkout gh-pages && rake doc && git checkout @{-1})
|
|
100
|
-
end
|
data/UPGRADING.md
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
## Articles
|
|
2
|
-
|
|
3
|
-
* [Migrating an ad-hoc URL slug system to FriendlyId](http://olivierlacan.com/posts/migrating-an-ad-hoc-url-slug-system-to-friendly-id/)
|
|
4
|
-
* [Pretty URLs with FriendlyId](http://railscasts.com/episodes/314-pretty-urls-with-friendlyid)
|
|
5
|
-
|
|
6
|
-
## Docs
|
|
7
|
-
|
|
8
|
-
The most current docs from the master branch can always be found
|
|
9
|
-
[here](http://norman.github.io/friendly_id).
|
|
10
|
-
|
|
11
|
-
Docs for older versions are also available:
|
|
12
|
-
|
|
13
|
-
* [5.0](http://norman.github.io/friendly_id/5.0/)
|
|
14
|
-
* [4.0](http://norman.github.io/friendly_id/4.0/)
|
|
15
|
-
* [3.3](http://norman.github.io/friendly_id/3.3/)
|
|
16
|
-
* [2.3](http://norman.github.io/friendly_id/2.3/)
|
|
17
|
-
|
|
18
|
-
## What Changed in Version 5.1
|
|
19
|
-
|
|
20
|
-
5.1 is a bugfix release, but bumps the minor version because some applications may be dependent
|
|
21
|
-
on the previously buggy behavior. The changes include:
|
|
22
|
-
|
|
23
|
-
* Blank strings can no longer be used as slugs.
|
|
24
|
-
* When the first slug candidate is rejected because it is reserved, additional candidates will
|
|
25
|
-
now be considered before marking the record as invalid.
|
|
26
|
-
* The `:finders` module is now compatible with Rails 4.2.
|
|
27
|
-
|
|
28
|
-
## What Changed in Version 5.0
|
|
29
|
-
|
|
30
|
-
As of version 5.0, FriendlyId uses [semantic versioning](http://semver.org/). Therefore, as you might
|
|
31
|
-
infer from the version number, 5.0 introduces changes incompatible with 4.0.
|
|
32
|
-
|
|
33
|
-
The most important changes are:
|
|
34
|
-
|
|
35
|
-
* Finders are no longer overridden by default. If you want to do friendly finds,
|
|
36
|
-
you must do `Model.friendly.find` rather than `Model.find`. You can however
|
|
37
|
-
restore FriendlyId 4-style finders by using the `:finders` addon:
|
|
38
|
-
|
|
39
|
-
```ruby
|
|
40
|
-
friendly_id :foo, use: :slugged # you must do MyClass.friendly.find('bar')
|
|
41
|
-
# or...
|
|
42
|
-
friendly_id :foo, use: [:slugged, :finders] # you can now do MyClass.find('bar')
|
|
43
|
-
```
|
|
44
|
-
* A new "candidates" functionality which makes it easy to set up a list of
|
|
45
|
-
alternate slugs that can be used to uniquely distinguish records, rather than
|
|
46
|
-
appending a sequence. For example:
|
|
47
|
-
|
|
48
|
-
```ruby
|
|
49
|
-
class Restaurant < ActiveRecord::Base
|
|
50
|
-
extend FriendlyId
|
|
51
|
-
friendly_id :slug_candidates, use: :slugged
|
|
52
|
-
|
|
53
|
-
# Try building a slug based on the following fields in
|
|
54
|
-
# increasing order of specificity.
|
|
55
|
-
def slug_candidates
|
|
56
|
-
[
|
|
57
|
-
:name,
|
|
58
|
-
[:name, :city],
|
|
59
|
-
[:name, :street, :city],
|
|
60
|
-
[:name, :street_number, :street, :city]
|
|
61
|
-
]
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
```
|
|
65
|
-
* Now that candidates have been added, FriendlyId no longer uses a numeric
|
|
66
|
-
sequence to differentiate conflicting slug, but rather a UUID (e.g. something
|
|
67
|
-
like `2bc08962-b3dd-4f29-b2e6-244710c86106`). This makes the
|
|
68
|
-
codebase simpler and more reliable when running concurrently, at the expense
|
|
69
|
-
of uglier ids being generated when there are conflicts.
|
|
70
|
-
* The default sequence separator has been changed from two dashes to one dash.
|
|
71
|
-
* Slugs are no longer regenerated when a record is saved. If you want to regenerate
|
|
72
|
-
a slug, you must explicitly set the slug column to nil:
|
|
73
|
-
|
|
74
|
-
```ruby
|
|
75
|
-
restaurant.friendly_id # joes-diner
|
|
76
|
-
restaurant.name = "The Plaza Diner"
|
|
77
|
-
restaurant.save!
|
|
78
|
-
restaurant.friendly_id # joes-diner
|
|
79
|
-
restaurant.slug = nil
|
|
80
|
-
restaurant.save!
|
|
81
|
-
restaurant.friendly_id # the-plaza-diner
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
You can restore some of the old behavior by overriding the
|
|
85
|
-
`should_generate_new_friendly_id?` method.
|
|
86
|
-
* The `friendly_id` Rails generator now generates an initializer showing you
|
|
87
|
-
how to do some common global configuration.
|
|
88
|
-
* The Globalize plugin has moved to a [separate gem](https://github.com/norman/friendly_id-globalize) (currently in alpha).
|
|
89
|
-
* The `:reserved` module no longer includes any default reserved words.
|
|
90
|
-
Previously it blocked "edit" and "new" everywhere. The default word list has
|
|
91
|
-
been moved to `config/initializers/friendly_id.rb` and now includes many more
|
|
92
|
-
words.
|
|
93
|
-
* The `:history` and `:scoped` addons can now be used together.
|
|
94
|
-
* Since it now requires Rails 4, FriendlyId also now requires Ruby 1.9.3 or
|
|
95
|
-
higher.
|
|
96
|
-
|
|
97
|
-
## Upgrading from FriendlyId 4.0
|
|
98
|
-
|
|
99
|
-
Run `rails generate friendly_id --skip-migration` and edit the initializer
|
|
100
|
-
generated in `config/initializers/friendly_id.rb`. This file contains notes
|
|
101
|
-
describing how to restore (or not) some of the defaults from FriendlyId 4.0.
|
|
102
|
-
|
|
103
|
-
If you want to use the `:history` and `:scoped` addons together, you must add a
|
|
104
|
-
`:scope` column to your friendly_id_slugs table and replace the unique index on
|
|
105
|
-
`:slug` and `:sluggable_type` with a unique index on those two columns, plus
|
|
106
|
-
the new `:scope` column.
|
|
107
|
-
|
|
108
|
-
A migration like this should be sufficient:
|
|
109
|
-
|
|
110
|
-
```ruby
|
|
111
|
-
add_column :friendly_id_slugs, :scope, :string
|
|
112
|
-
remove_index :friendly_id_slugs, [:slug, :sluggable_type]
|
|
113
|
-
add_index :friendly_id_slugs, [:slug, :sluggable_type]
|
|
114
|
-
add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], unique: true
|
|
115
|
-
```
|
data/bench.rb
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
require File.expand_path("../test/helper", __FILE__)
|
|
2
|
-
require "ffaker"
|
|
3
|
-
|
|
4
|
-
N = 10000
|
|
5
|
-
|
|
6
|
-
def transaction
|
|
7
|
-
ActiveRecord::Base.transaction do
|
|
8
|
-
yield
|
|
9
|
-
|
|
10
|
-
raise ActiveRecord::Rollback
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
class Array
|
|
15
|
-
def rand
|
|
16
|
-
self[Kernel.rand(length)]
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
Book = Class.new ActiveRecord::Base
|
|
21
|
-
|
|
22
|
-
class Journalist < ActiveRecord::Base
|
|
23
|
-
extend FriendlyId
|
|
24
|
-
friendly_id :name, use: :slugged
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class Manual < ActiveRecord::Base
|
|
28
|
-
extend FriendlyId
|
|
29
|
-
friendly_id :name, use: :history
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
class Restaurant < ActiveRecord::Base
|
|
33
|
-
extend FriendlyId
|
|
34
|
-
friendly_id :name, use: :finders
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
BOOKS = []
|
|
38
|
-
JOURNALISTS = []
|
|
39
|
-
MANUALS = []
|
|
40
|
-
RESTAURANTS = []
|
|
41
|
-
|
|
42
|
-
100.times do
|
|
43
|
-
name = FFaker::Name.name
|
|
44
|
-
BOOKS << (Book.create! name: name).id
|
|
45
|
-
JOURNALISTS << (Journalist.create! name: name).friendly_id
|
|
46
|
-
MANUALS << (Manual.create! name: name).friendly_id
|
|
47
|
-
RESTAURANTS << (Restaurant.create! name: name).friendly_id
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
ActiveRecord::Base.connection.execute "UPDATE manuals SET slug = NULL"
|
|
51
|
-
|
|
52
|
-
Benchmark.bmbm do |x|
|
|
53
|
-
x.report "find (without FriendlyId)" do
|
|
54
|
-
N.times { Book.find BOOKS.rand }
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
x.report "find (in-table slug)" do
|
|
58
|
-
N.times { Journalist.friendly.find JOURNALISTS.rand }
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
x.report "find (in-table slug; using finders module)" do
|
|
62
|
-
N.times { Restaurant.find RESTAURANTS.rand }
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
x.report "find (external slug)" do
|
|
66
|
-
N.times { Manual.friendly.find MANUALS.rand }
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
x.report "insert (without FriendlyId)" do
|
|
70
|
-
N.times { transaction { Book.create name: FFaker::Name.name } }
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
x.report "insert (in-table-slug)" do
|
|
74
|
-
N.times { transaction { Journalist.create name: FFaker::Name.name } }
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
x.report "insert (in-table-slug; using finders module)" do
|
|
78
|
-
N.times { transaction { Restaurant.create name: FFaker::Name.name } }
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
x.report "insert (external slug)" do
|
|
82
|
-
N.times { transaction { Manual.create name: FFaker::Name.name } }
|
|
83
|
-
end
|
|
84
|
-
end
|
data/friendly_id.gemspec
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require File.expand_path("../lib/friendly_id/version", __FILE__)
|
|
2
|
-
|
|
3
|
-
Gem::Specification.new do |s|
|
|
4
|
-
s.name = "friendly_id"
|
|
5
|
-
s.version = FriendlyId::VERSION
|
|
6
|
-
s.authors = ["Norman Clarke", "Philip Arndt"]
|
|
7
|
-
s.email = ["norman@njclarke.com", "gems@p.arndt.io"]
|
|
8
|
-
s.homepage = "https://github.com/norman/friendly_id"
|
|
9
|
-
s.summary = "A comprehensive slugging and pretty-URL plugin."
|
|
10
|
-
s.files = `git ls-files`.split("\n")
|
|
11
|
-
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
|
12
|
-
s.require_paths = ["lib"]
|
|
13
|
-
s.license = "MIT"
|
|
14
|
-
|
|
15
|
-
s.required_ruby_version = ">= 2.1.0"
|
|
16
|
-
|
|
17
|
-
s.add_dependency "activerecord", ">= 4.0.0"
|
|
18
|
-
|
|
19
|
-
s.add_development_dependency "coveralls"
|
|
20
|
-
s.add_development_dependency "railties", ">= 4.0"
|
|
21
|
-
s.add_development_dependency "minitest", "~> 5.3"
|
|
22
|
-
s.add_development_dependency "mocha", "~> 2.1"
|
|
23
|
-
s.add_development_dependency "yard"
|
|
24
|
-
s.add_development_dependency "i18n"
|
|
25
|
-
s.add_development_dependency "ffaker"
|
|
26
|
-
s.add_development_dependency "simplecov"
|
|
27
|
-
|
|
28
|
-
s.description = "FriendlyId is the \"Swiss Army bulldozer\" of slugging " \
|
|
29
|
-
"and permalink plugins for Active Record. It lets you create pretty URLs " \
|
|
30
|
-
"and work with human-friendly strings as if they were numeric ids."
|
|
31
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
source "https://rubygems.org"
|
|
2
|
-
|
|
3
|
-
gemspec path: "../"
|
|
4
|
-
|
|
5
|
-
gem "activerecord", "~> 6.0.0"
|
|
6
|
-
gem "railties", "~> 6.0.0"
|
|
7
|
-
|
|
8
|
-
# Database Configuration
|
|
9
|
-
group :development, :test do
|
|
10
|
-
platforms :jruby do
|
|
11
|
-
gem "activerecord-jdbcmysql-adapter", "~> 51.1"
|
|
12
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 51.1"
|
|
13
|
-
gem "kramdown"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
platforms :ruby, :rbx do
|
|
17
|
-
gem "sqlite3"
|
|
18
|
-
gem "mysql2"
|
|
19
|
-
gem "pg"
|
|
20
|
-
gem "redcarpet"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
source "https://rubygems.org"
|
|
2
|
-
|
|
3
|
-
gemspec path: "../"
|
|
4
|
-
|
|
5
|
-
gem "activerecord", "~> 6.1.4"
|
|
6
|
-
gem "railties", "~> 6.1.4"
|
|
7
|
-
|
|
8
|
-
# Database Configuration
|
|
9
|
-
group :development, :test do
|
|
10
|
-
platforms :jruby do
|
|
11
|
-
gem "activerecord-jdbcmysql-adapter", "~> 61.0"
|
|
12
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
|
|
13
|
-
gem "kramdown"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
platforms :ruby, :rbx do
|
|
17
|
-
gem "sqlite3"
|
|
18
|
-
gem "mysql2"
|
|
19
|
-
gem "pg"
|
|
20
|
-
gem "redcarpet"
|
|
21
|
-
end
|
|
22
|
-
end
|