friendly_id 5.5.1 → 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/Changelog.md +4 -1
- data/README.md +3 -3
- data/lib/friendly_id/history.rb +2 -2
- data/lib/friendly_id/slug_generator.rb +15 -0
- data/lib/friendly_id/slugged.rb +19 -1
- data/lib/friendly_id/version.rb +1 -1
- metadata +5 -76
- checksums.yaml.gz.sig +0 -0
- 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/test.yml +0 -62
- data/.gitignore +0 -14
- data/.yardopts +0 -8
- data/CONTRIBUTING.md +0 -11
- data/Gemfile +0 -23
- data/Rakefile +0 -104
- data/UPGRADING.md +0 -115
- data/bench.rb +0 -84
- data/certs/parndt.pem +0 -27
- data/friendly_id.gemspec +0 -36
- data/gemfiles/Gemfile.rails-5.2.rb +0 -22
- 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/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 -31
- 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
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
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/Changelog.md
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
We would like to think our many [contributors](https://github.com/norman/friendly_id/graphs/contributors) for
|
|
4
4
|
suggestions, ideas and improvements to FriendlyId.
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## 5.6.0 (2025-12-07)
|
|
7
|
+
|
|
8
|
+
* Add: `treat_numeric_as_conflict` option to prevent ambiguous numeric slugs. ([#1037](https://github.com/norman/friendly_id/pull/1037))
|
|
9
|
+
* Fix: history not using `parse_friendly_id`. ([#1020](https://github.com/norman/friendly_id/pull/1020))
|
|
7
10
|
|
|
8
11
|
## 5.5.1 (2023-11-13)
|
|
9
12
|
|
data/README.md
CHANGED
|
@@ -39,7 +39,7 @@ FriendlyId offers many advanced features, including:
|
|
|
39
39
|
Add this line to your application's Gemfile:
|
|
40
40
|
|
|
41
41
|
```ruby
|
|
42
|
-
gem 'friendly_id', '~> 5.
|
|
42
|
+
gem 'friendly_id', '~> 5.5.0'
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
Note: You MUST use 5.0.0 or greater for Rails 4.0+.
|
|
@@ -108,8 +108,8 @@ User.find_each(&:save)
|
|
|
108
108
|
|
|
109
109
|
### `:allow_nil`
|
|
110
110
|
|
|
111
|
-
You can pass `allow_nil: true` to the `friendly.find()` method if you
|
|
112
|
-
avoid raising `ActiveRecord::RecordNotFound` and accept
|
|
111
|
+
You can pass `allow_nil: true` to the `friendly.find()` method if you want to
|
|
112
|
+
avoid raising `ActiveRecord::RecordNotFound` and accept `nil`.
|
|
113
113
|
|
|
114
114
|
#### Example
|
|
115
115
|
|
data/lib/friendly_id/history.rb
CHANGED
|
@@ -85,13 +85,13 @@ module FriendlyId
|
|
|
85
85
|
include ::FriendlyId::FinderMethods
|
|
86
86
|
|
|
87
87
|
def exists_by_friendly_id?(id)
|
|
88
|
-
super || joins(:slugs).where(slug_history_clause(id)).exists?
|
|
88
|
+
super || joins(:slugs).where(slug_history_clause(parse_friendly_id(id))).exists?
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
private
|
|
92
92
|
|
|
93
93
|
def first_by_friendly_id(id)
|
|
94
|
-
super || slug_table_record(id)
|
|
94
|
+
super || slug_table_record(parse_friendly_id(id))
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
def slug_table_record(id)
|
|
@@ -12,6 +12,10 @@ module FriendlyId
|
|
|
12
12
|
return false if @config.reserved_words.include?(slug)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
if @config.treat_numeric_as_conflict && purely_numeric_slug?(slug)
|
|
16
|
+
return false
|
|
17
|
+
end
|
|
18
|
+
|
|
15
19
|
!@scope.exists_by_friendly_id?(slug)
|
|
16
20
|
end
|
|
17
21
|
|
|
@@ -19,5 +23,16 @@ module FriendlyId
|
|
|
19
23
|
candidates.each { |c| return c if available?(c) }
|
|
20
24
|
nil
|
|
21
25
|
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def purely_numeric_slug?(slug)
|
|
30
|
+
return false unless slug
|
|
31
|
+
begin
|
|
32
|
+
Integer(slug, 10).to_s == slug.to_s
|
|
33
|
+
rescue ArgumentError, TypeError
|
|
34
|
+
false
|
|
35
|
+
end
|
|
36
|
+
end
|
|
22
37
|
end
|
|
23
38
|
end
|
data/lib/friendly_id/slugged.rb
CHANGED
|
@@ -155,6 +155,24 @@ module FriendlyId
|
|
|
155
155
|
# You can change this with the {FriendlyId::Slugged::Configuration#sequence_separator
|
|
156
156
|
# sequence_separator} configuration option.
|
|
157
157
|
#
|
|
158
|
+
# #### Avoiding Numeric Slugs
|
|
159
|
+
#
|
|
160
|
+
# Purely numeric slugs like "123" can create ambiguity in Rails routing - they could
|
|
161
|
+
# be interpreted as either a friendly slug or a database ID. To prevent this, you can
|
|
162
|
+
# configure FriendlyId to treat numeric slugs as conflicts and add a UUID suffix:
|
|
163
|
+
#
|
|
164
|
+
# class Product < ActiveRecord::Base
|
|
165
|
+
# extend FriendlyId
|
|
166
|
+
# friendly_id :sku, use: :slugged
|
|
167
|
+
# friendly_id_config.treat_numeric_as_conflict = true
|
|
168
|
+
# end
|
|
169
|
+
#
|
|
170
|
+
# product = Product.create! sku: "123"
|
|
171
|
+
# product.slug #=> "123-f9f3789a-daec-4156-af1d-fab81aa16ee5"
|
|
172
|
+
#
|
|
173
|
+
# This only affects purely numeric slugs. Alphanumeric slugs like "product-123"
|
|
174
|
+
# or "abc123" will work normally.
|
|
175
|
+
#
|
|
158
176
|
# #### Providing Your Own Slug Processing Method
|
|
159
177
|
#
|
|
160
178
|
# You can override {FriendlyId::Slugged#normalize_friendly_id} in your model for
|
|
@@ -386,7 +404,7 @@ module FriendlyId
|
|
|
386
404
|
# {FriendlyId::Configuration FriendlyId::Configuration}.
|
|
387
405
|
module Configuration
|
|
388
406
|
attr_writer :slug_column, :slug_limit, :sequence_separator
|
|
389
|
-
attr_accessor :slug_generator_class
|
|
407
|
+
attr_accessor :slug_generator_class, :treat_numeric_as_conflict
|
|
390
408
|
|
|
391
409
|
# Makes FriendlyId use the slug column for querying.
|
|
392
410
|
# @return String The slug column.
|
data/lib/friendly_id/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,43 +1,14 @@
|
|
|
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
|
|
8
8
|
- Philip Arndt
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
|
-
cert_chain:
|
|
12
|
-
-
|
|
13
|
-
-----BEGIN CERTIFICATE-----
|
|
14
|
-
MIIEljCCAv6gAwIBAgIBATANBgkqhkiG9w0BAQsFADBRMREwDwYDVQQDDAhydWJ5
|
|
15
|
-
Z2VtczERMA8GCgmSJomT8ixkARkWAXAxFTATBgoJkiaJk/IsZAEZFgVhcm5kdDES
|
|
16
|
-
MBAGCgmSJomT8ixkARkWAmlvMB4XDTIyMTExNTIyMjQzMFoXDTIzMTExNTIyMjQz
|
|
17
|
-
MFowUTERMA8GA1UEAwwIcnVieWdlbXMxETAPBgoJkiaJk/IsZAEZFgFwMRUwEwYK
|
|
18
|
-
CZImiZPyLGQBGRYFYXJuZHQxEjAQBgoJkiaJk/IsZAEZFgJpbzCCAaIwDQYJKoZI
|
|
19
|
-
hvcNAQEBBQADggGPADCCAYoCggGBAMPq2bIEO+BmmBeuidSySK7xlL/LWBHzyDxw
|
|
20
|
-
EMgWsHqJMDZYCZI4WoWbSTSSLrp5zPXLWN0hB23u3dxFp4RVygTTZkc8k05mteab
|
|
21
|
-
fdREGgdcP+mY8/ASQSvb1VW6IM51Srgjy1SK0S5Qf3HAiQafFvRsxRkY0SWyth24
|
|
22
|
-
ne/7HG667vHQ1+t0VFl8twupJE9S8p2zgX3eZBl2yRNm/kE5reUsOLvmS58Iri/X
|
|
23
|
-
9tnz0SGkzrKkim9OIByq7XkFLL3oaIyfbBVgOWilM5pvxj/xNuRH7EIM6aE3q0UZ
|
|
24
|
-
xo7o9u9Iz2zApDEjejByPjxWAhLuP3v3bJyinRFE1rO47lEM/s6KM/6YooxvgYIN
|
|
25
|
-
miYYFRtTj9nmKEMv6+h1mZ1/ZwqStTTRh/T90T65dcgsoqRd0JNvpNRjFrYH5cuj
|
|
26
|
-
QZWMl/FE6AADm0GXa34ZiTQx3Wx2ctqJLFak8+imPwes90nCpiYmgaZpwBI+shjU
|
|
27
|
-
AddbPDNq+EoxPMWTh0Er3w76fywOWQIDAQABo3kwdzAJBgNVHRMEAjAAMAsGA1Ud
|
|
28
|
-
DwQEAwIEsDAdBgNVHQ4EFgQUxRJaTQZmtkN8FKUWVHKc2riND18wHgYDVR0RBBcw
|
|
29
|
-
FYETcnVieWdlbXNAcC5hcm5kdC5pbzAeBgNVHRIEFzAVgRNydWJ5Z2Vtc0BwLmFy
|
|
30
|
-
bmR0LmlvMA0GCSqGSIb3DQEBCwUAA4IBgQBSRGMkZ2dvJ0LSjFz+rIt3G3AZMbKD
|
|
31
|
-
tjaaQRuC9rOkrl3Rml6h9j7cHYiM0wkTjXneFNySc8jWmM/jKnxiiUfUK9r1XL4n
|
|
32
|
-
71tz39+MD2lIpLVVEQ69MIoUseppNUTCg0mNghSDYNwISMD/hoWwbJudBi56DbhE
|
|
33
|
-
xkulLbw8qtcEE+iilIKibe+eJF4platKScsOA7d1AuilR1/S245UzeqwwyI52/xK
|
|
34
|
-
dfoP928X9Tb/48+83lWUgAgCQOd6WdfCpgQ5H6R90lc8L7OfuDR/vgcmSOTsNVgG
|
|
35
|
-
1TC3b2FISS0p0qfZsiS7BXh+ARoBKLXsV1a7WR36X0dUpajvk+zzBGrFCdbW43Gx
|
|
36
|
-
wmJzIksYnf9Ktg8Ux+FLcRBGw4qEIyWvqmS0obB1Hke68rTg0uNTFcKXsNw33XF5
|
|
37
|
-
fw1cbj95g7OPe0feGK8+afXh/L38vx/hIIOGlUEZ+HaWL2Dki/7vRGvda8dfOpG5
|
|
38
|
-
bJfaoyKbVsrK+gGKFJv860zsO8lg6BGLsUw=
|
|
39
|
-
-----END CERTIFICATE-----
|
|
40
|
-
date: 2023-11-12 00:00:00.000000000 Z
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
41
12
|
dependencies:
|
|
42
13
|
- !ruby/object:Gem::Dependency
|
|
43
14
|
name: activerecord
|
|
@@ -170,33 +141,14 @@ description: FriendlyId is the "Swiss Army bulldozer" of slugging and permalink
|
|
|
170
141
|
as if they were numeric ids.
|
|
171
142
|
email:
|
|
172
143
|
- norman@njclarke.com
|
|
173
|
-
- p
|
|
144
|
+
- gems@p.arndt.io
|
|
174
145
|
executables: []
|
|
175
146
|
extensions: []
|
|
176
147
|
extra_rdoc_files: []
|
|
177
148
|
files:
|
|
178
|
-
- ".gemtest"
|
|
179
|
-
- ".github/FUNDING.yml"
|
|
180
|
-
- ".github/dependabot.yml"
|
|
181
|
-
- ".github/stale.yml"
|
|
182
|
-
- ".github/workflows/test.yml"
|
|
183
|
-
- ".gitignore"
|
|
184
|
-
- ".yardopts"
|
|
185
|
-
- CONTRIBUTING.md
|
|
186
149
|
- Changelog.md
|
|
187
|
-
- Gemfile
|
|
188
150
|
- MIT-LICENSE
|
|
189
151
|
- README.md
|
|
190
|
-
- Rakefile
|
|
191
|
-
- UPGRADING.md
|
|
192
|
-
- bench.rb
|
|
193
|
-
- certs/parndt.pem
|
|
194
|
-
- friendly_id.gemspec
|
|
195
|
-
- gemfiles/Gemfile.rails-5.2.rb
|
|
196
|
-
- gemfiles/Gemfile.rails-6.0.rb
|
|
197
|
-
- gemfiles/Gemfile.rails-6.1.rb
|
|
198
|
-
- gemfiles/Gemfile.rails-7.0.rb
|
|
199
|
-
- guide.rb
|
|
200
152
|
- lib/friendly_id.rb
|
|
201
153
|
- lib/friendly_id/.gitattributes
|
|
202
154
|
- lib/friendly_id/base.rb
|
|
@@ -218,32 +170,10 @@ files:
|
|
|
218
170
|
- lib/friendly_id/slugged.rb
|
|
219
171
|
- lib/friendly_id/version.rb
|
|
220
172
|
- lib/generators/friendly_id_generator.rb
|
|
221
|
-
- test/base_test.rb
|
|
222
|
-
- test/benchmarks/finders.rb
|
|
223
|
-
- test/benchmarks/object_utils.rb
|
|
224
|
-
- test/candidates_test.rb
|
|
225
|
-
- test/configuration_test.rb
|
|
226
|
-
- test/core_test.rb
|
|
227
|
-
- test/databases.yml
|
|
228
|
-
- test/finders_test.rb
|
|
229
|
-
- test/generator_test.rb
|
|
230
|
-
- test/helper.rb
|
|
231
|
-
- test/history_test.rb
|
|
232
|
-
- test/numeric_slug_test.rb
|
|
233
|
-
- test/object_utils_test.rb
|
|
234
|
-
- test/reserved_test.rb
|
|
235
|
-
- test/schema.rb
|
|
236
|
-
- test/scoped_test.rb
|
|
237
|
-
- test/sequentially_slugged_test.rb
|
|
238
|
-
- test/shared.rb
|
|
239
|
-
- test/simple_i18n_test.rb
|
|
240
|
-
- test/slugged_test.rb
|
|
241
|
-
- test/sti_test.rb
|
|
242
173
|
homepage: https://github.com/norman/friendly_id
|
|
243
174
|
licenses:
|
|
244
175
|
- MIT
|
|
245
176
|
metadata: {}
|
|
246
|
-
post_install_message:
|
|
247
177
|
rdoc_options: []
|
|
248
178
|
require_paths:
|
|
249
179
|
- lib
|
|
@@ -258,8 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
258
188
|
- !ruby/object:Gem::Version
|
|
259
189
|
version: '0'
|
|
260
190
|
requirements: []
|
|
261
|
-
rubygems_version:
|
|
262
|
-
signing_key:
|
|
191
|
+
rubygems_version: 4.0.6
|
|
263
192
|
specification_version: 4
|
|
264
193
|
summary: A comprehensive slugging and pretty-URL plugin.
|
|
265
194
|
test_files: []
|
checksums.yaml.gz.sig
DELETED
|
Binary file
|
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
|
data/.github/workflows/test.yml
DELETED
|
@@ -1,62 +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: [ '7.0', '6.1', '6.0' ]
|
|
14
|
-
ruby: [ '2.6', '2.7', '3.0', '3.1', '3.2' ]
|
|
15
|
-
exclude:
|
|
16
|
-
- ruby: '2.6'
|
|
17
|
-
gemfile: '7.0'
|
|
18
|
-
- ruby: '3.2'
|
|
19
|
-
gemfile: '6.0'
|
|
20
|
-
- ruby: '3.2'
|
|
21
|
-
gemfile: '6.1'
|
|
22
|
-
fail-fast: false
|
|
23
|
-
runs-on: ubuntu-latest
|
|
24
|
-
|
|
25
|
-
env:
|
|
26
|
-
BUNDLE_GEMFILE: gemfiles/Gemfile.rails-${{ matrix.gemfile }}.rb
|
|
27
|
-
CI: true
|
|
28
|
-
COVERALLS: true
|
|
29
|
-
DB: ${{ matrix.database }}
|
|
30
|
-
MYSQL_PASSWORD: root
|
|
31
|
-
PGHOST: localhost
|
|
32
|
-
PGPASSWORD: runner
|
|
33
|
-
PGUSER: runner
|
|
34
|
-
RAILS_ENV: test
|
|
35
|
-
|
|
36
|
-
name: ${{ matrix.ruby }} ${{ matrix.database }} rails-${{ matrix.gemfile }}
|
|
37
|
-
steps:
|
|
38
|
-
- uses: actions/checkout@v3
|
|
39
|
-
|
|
40
|
-
- run: sudo apt-get update && sudo apt-get install libsqlite3-dev -y
|
|
41
|
-
|
|
42
|
-
- name: "Set up MySQL using VM's server"
|
|
43
|
-
if: ${{ env.DB == 'mysql' }}
|
|
44
|
-
run: |
|
|
45
|
-
sudo apt-get install libmysqlclient-dev -y
|
|
46
|
-
sudo systemctl start mysql.service
|
|
47
|
-
|
|
48
|
-
- name: "Set up PostgreSQL using VM's server"
|
|
49
|
-
if: ${{ env.DB == 'postgresql' }}
|
|
50
|
-
run: |
|
|
51
|
-
sudo apt-get install libpq-dev -y
|
|
52
|
-
sudo systemctl start postgresql.service
|
|
53
|
-
sudo -u postgres psql -c "CREATE USER runner WITH SUPERUSER PASSWORD 'runner'"
|
|
54
|
-
sudo -u postgres createdb runner
|
|
55
|
-
|
|
56
|
-
- uses: ruby/setup-ruby@v1
|
|
57
|
-
with:
|
|
58
|
-
bundler-cache: true
|
|
59
|
-
ruby-version: ${{ matrix.ruby }}
|
|
60
|
-
|
|
61
|
-
- run: bundle exec rake db:{create,up}
|
|
62
|
-
- 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,104 +0,0 @@
|
|
|
1
|
-
require "rubygems"
|
|
2
|
-
require "rake/testtask"
|
|
3
|
-
|
|
4
|
-
task default: :test
|
|
5
|
-
|
|
6
|
-
task :load_path do
|
|
7
|
-
%w[lib test].each do |path|
|
|
8
|
-
$LOAD_PATH.unshift(File.expand_path("../#{path}", __FILE__))
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
Rake::TestTask.new do |t|
|
|
13
|
-
t.libs << "test"
|
|
14
|
-
t.test_files = FileList["test/*_test.rb"]
|
|
15
|
-
t.verbose = true
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
desc "Remove temporary files"
|
|
19
|
-
task :clean do
|
|
20
|
-
`rm -rf *.gem doc pkg coverage`
|
|
21
|
-
%x(rm -f `find . -name '*.rbc'`)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
desc "Build the gem"
|
|
25
|
-
task :gem do
|
|
26
|
-
`gem build friendly_id.gemspec`
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
desc "Build YARD documentation"
|
|
30
|
-
task :yard do
|
|
31
|
-
puts `bundle exec yard`
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
desc "Run benchmarks"
|
|
35
|
-
task bench: :load_path do
|
|
36
|
-
require File.expand_path("../bench", __FILE__)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
desc "Run benchmarks on finders"
|
|
40
|
-
task bench_finders: :load_path do
|
|
41
|
-
require File.expand_path("../test/benchmarks/finders", __FILE__)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
desc "Run benchmarks on ObjectUtils"
|
|
45
|
-
task bench_object_utils: :load_path do
|
|
46
|
-
require File.expand_path("../test/benchmarks/object_utils", __FILE__)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
desc "Generate Guide.md"
|
|
50
|
-
task :guide do
|
|
51
|
-
load File.expand_path("../guide.rb", __FILE__)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
namespace :test do
|
|
55
|
-
desc "Run each test class in a separate process"
|
|
56
|
-
task :isolated do
|
|
57
|
-
dir = File.expand_path("../test", __FILE__)
|
|
58
|
-
Dir["#{dir}/*_test.rb"].each do |test|
|
|
59
|
-
puts "Running #{test}:"
|
|
60
|
-
puts `ruby -Ilib -Itest #{test}`
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
namespace :db do
|
|
66
|
-
desc "Create the database"
|
|
67
|
-
task create: :load_path do
|
|
68
|
-
require "helper"
|
|
69
|
-
driver = FriendlyId::Test::Database.driver
|
|
70
|
-
config = FriendlyId::Test::Database.config[driver]
|
|
71
|
-
commands = {
|
|
72
|
-
"mysql" => "mysql -h #{config["host"]} -P #{config["port"]} -u #{config["username"]} --password=#{config["password"]} -e 'create database #{config["database"]};' >/dev/null",
|
|
73
|
-
"postgres" => "psql -c 'create database #{config["database"]};' -U #{config["username"]} >/dev/null"
|
|
74
|
-
}
|
|
75
|
-
`#{commands[driver] || true}`
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
desc "Drop the database"
|
|
79
|
-
task drop: :load_path do
|
|
80
|
-
require "helper"
|
|
81
|
-
driver = FriendlyId::Test::Database.driver
|
|
82
|
-
config = FriendlyId::Test::Database.config[driver]
|
|
83
|
-
commands = {
|
|
84
|
-
"mysql" => "mysql -h #{config["host"]} -P #{config["port"]} -u #{config["username"]} --password=#{config["password"]} -e 'drop database #{config["database"]};' >/dev/null",
|
|
85
|
-
"postgres" => "psql -c 'drop database #{config["database"]};' -U #{config["username"]} >/dev/null"
|
|
86
|
-
}
|
|
87
|
-
`#{commands[driver] || true}`
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
desc "Set up the database schema"
|
|
91
|
-
task up: :load_path do
|
|
92
|
-
require "helper"
|
|
93
|
-
FriendlyId::Test::Schema.up
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
desc "Drop and recreate the database schema"
|
|
97
|
-
task reset: [:drop, :create]
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
task doc: :yard
|
|
101
|
-
|
|
102
|
-
task :docs do
|
|
103
|
-
sh %(git checkout gh-pages && rake doc && git checkout @{-1})
|
|
104
|
-
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
|
-
```
|