friendly_id 5.2.1 → 5.2.2
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/.travis.yml +8 -9
- data/Changelog.md +6 -0
- data/README.md +5 -0
- data/gemfiles/Gemfile.rails-5.0.rb +2 -2
- data/lib/friendly_id/base.rb +3 -0
- data/lib/friendly_id/finder_methods.rb +4 -1
- data/lib/friendly_id/initializer.rb +4 -0
- data/lib/friendly_id/slugged.rb +58 -5
- data/lib/friendly_id/version.rb +1 -1
- data/test/schema.rb +1 -2
- data/test/slugged_test.rb +26 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e2080c5099215c8dafa04072948b2ac30907bb8
|
4
|
+
data.tar.gz: bee56373516dd5ed394d7de3bc554a08560d5433
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 015d359758f15798d9f51ff5cd22462510a48e523fa4b3c0c4a7a8aefd8b370039dce2bc78484a54d05be82e0b7b57284d4763d943eaec35c1418fb5b23cc2ba
|
7
|
+
data.tar.gz: 66ebbb5b6f6345c6beb0d5c4668ba61d5f9e26b2cff24ab8c8591ed36489559584f24fb00ef41b52aefc568ebc5fd121a200d89db8a04948a23a06aa100cb758
|
data/.travis.yml
CHANGED
@@ -2,10 +2,10 @@ language: ruby
|
|
2
2
|
cache: bundler
|
3
3
|
|
4
4
|
rvm:
|
5
|
+
- 2.4.0
|
5
6
|
- 2.3.0
|
6
7
|
- 2.2.0
|
7
8
|
- 2.1.0
|
8
|
-
- 2.0.0
|
9
9
|
- jruby-9.0.4.0
|
10
10
|
|
11
11
|
env:
|
@@ -18,20 +18,19 @@ gemfile:
|
|
18
18
|
- gemfiles/Gemfile.rails-4.2.rb
|
19
19
|
- gemfiles/Gemfile.rails-5.0.rb
|
20
20
|
|
21
|
+
before_install:
|
22
|
+
- gem update bundler
|
23
|
+
|
21
24
|
matrix:
|
22
|
-
allow_failures:
|
23
|
-
- rvm: jruby-19mode
|
24
|
-
gemfile: gemfiles/Gemfile.rails-4.2.rb
|
25
|
-
env: DB=postgres
|
26
|
-
- rvm: jruby-9.0.4.0
|
27
|
-
gemfile: gemfiles/Gemfile.rails-5.0.rb
|
28
25
|
exclude:
|
29
|
-
- rvm: 2.0.0
|
30
|
-
gemfile: gemfiles/Gemfile.rails-5.0.rb
|
31
26
|
- rvm: 2.1.0
|
32
27
|
gemfile: gemfiles/Gemfile.rails-5.0.rb
|
33
28
|
- rvm: 2.2.0
|
34
29
|
gemfile: gemfiles/Gemfile.rails-5.0.rb
|
30
|
+
- rvm: 2.4.0
|
31
|
+
gemfile: gemfiles/Gemfile.rails-4.0.rb
|
32
|
+
- rvm: 2.4.0
|
33
|
+
gemfile: gemfiles/Gemfile.rails-4.1.rb
|
35
34
|
|
36
35
|
sudo: false
|
37
36
|
|
data/Changelog.md
CHANGED
@@ -3,6 +3,12 @@
|
|
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
|
+
## 5.2.2 (2017-09-13)
|
7
|
+
|
8
|
+
* Prevent warning on db:migrate in Rails 5.1 ([#826](https://github.com/norman/friendly_id/pull/826)).
|
9
|
+
* Allow to set size limit for slug ([#809](https://github.com/norman/friendly_id/pull/809)).
|
10
|
+
* Update specs and drop support for ruby 2.0.0 ([#824](https://github.com/norman/friendly_id/pull/824)).
|
11
|
+
|
6
12
|
## 5.2.1 (2017-04-09)
|
7
13
|
|
8
14
|
* Change ActiveRecord::Base to ApplicationRecord ([#782](https://github.com/norman/friendly_id/pull/782)).
|
data/README.md
CHANGED
@@ -174,6 +174,11 @@ gem 'friendly_id', '~> 5.1.0' # Note: You MUST use 5.0.0 or greater for Rails 4.
|
|
174
174
|
```
|
175
175
|
```shell
|
176
176
|
rails generate friendly_id
|
177
|
+
```
|
178
|
+
>Temp solution for Rails 5.1+ : Before running the migration, go into the generated migration file and specify the Rails version:
|
179
|
+
`class CreateFriendlyIdSlugs < ActiveRecord::Migration[5.1]`
|
180
|
+
```
|
181
|
+
```shell
|
177
182
|
rails generate scaffold user name:string slug:string:uniq
|
178
183
|
rake db:migrate
|
179
184
|
```
|
@@ -9,8 +9,8 @@ gem 'i18n', '~> 0.7.0'
|
|
9
9
|
# Database Configuration
|
10
10
|
group :development, :test do
|
11
11
|
platforms :jruby do
|
12
|
-
gem 'activerecord-jdbcmysql-adapter', '
|
13
|
-
gem 'activerecord-jdbcpostgresql-adapter', '
|
12
|
+
gem 'activerecord-jdbcmysql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter.git', branch: 'rails-5'
|
13
|
+
gem 'activerecord-jdbcpostgresql-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter.git', branch: 'rails-5'
|
14
14
|
gem 'kramdown'
|
15
15
|
end
|
16
16
|
|
data/lib/friendly_id/base.rb
CHANGED
@@ -178,6 +178,9 @@ often better and easier to use {FriendlyId::Slugged slugs}.
|
|
178
178
|
# Configures the name of the column where FriendlyId will store the slug.
|
179
179
|
# Defaults to `:slug`.
|
180
180
|
#
|
181
|
+
# @option options [Integer] :slug_limit Available when using `:slugged`.
|
182
|
+
# Configures the limit of the slug. This option has no default value.
|
183
|
+
#
|
181
184
|
# @option options [Symbol] :slug_generator_class Available when using `:slugged`.
|
182
185
|
# Sets the class used to generate unique slugs. You should not specify this
|
183
186
|
# unless you're doing some extensive hacking on FriendlyId. Defaults to
|
@@ -43,7 +43,10 @@ module FriendlyId
|
|
43
43
|
private
|
44
44
|
|
45
45
|
def potential_primary_key?(id)
|
46
|
-
|
46
|
+
key_type = primary_key_type
|
47
|
+
# Hook for "ActiveModel::Type::Integer" instance.
|
48
|
+
key_type = key_type.type if key_type.respond_to?(:type)
|
49
|
+
case key_type
|
47
50
|
when :integer
|
48
51
|
Integer(id, 10) rescue false
|
49
52
|
when :uuid
|
@@ -52,6 +52,10 @@ FriendlyId.defaults do |config|
|
|
52
52
|
#
|
53
53
|
# config.slug_column = 'slug'
|
54
54
|
#
|
55
|
+
# By default, slug has no size limit, but you can change it if you wish.
|
56
|
+
#
|
57
|
+
# config.slug_limit = 255
|
58
|
+
#
|
55
59
|
# When FriendlyId can not generate a unique ID from your base method, it appends
|
56
60
|
# a UUID, separated by a single dash. You can configure the character used as the
|
57
61
|
# separator. If you're upgrading from FriendlyId 4, you may wish to replace this
|
data/lib/friendly_id/slugged.rb
CHANGED
@@ -288,7 +288,9 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
288
288
|
# @param [#to_s] value The value used as the basis of the slug.
|
289
289
|
# @return The candidate slug text, without a sequence.
|
290
290
|
def normalize_friendly_id(value)
|
291
|
-
value.to_s.parameterize
|
291
|
+
value = value.to_s.parameterize
|
292
|
+
value = value[0...friendly_id_config.slug_limit] if friendly_id_config.slug_limit
|
293
|
+
value
|
292
294
|
end
|
293
295
|
|
294
296
|
# Whether to generate a new slug.
|
@@ -299,10 +301,56 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
299
301
|
send(friendly_id_config.slug_column).nil? && !send(friendly_id_config.base).nil?
|
300
302
|
end
|
301
303
|
|
304
|
+
# Public: Resolve conflicts.
|
305
|
+
#
|
306
|
+
# This method adds UUID to first candidate and truncates (if `slug_limit` is set).
|
307
|
+
#
|
308
|
+
# Examples:
|
309
|
+
#
|
310
|
+
# resolve_friendly_id_conflict(['12345'])
|
311
|
+
# # => '12345-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
312
|
+
#
|
313
|
+
# FriendlyId.defaults { |config| config.slug_limit = 40 }
|
314
|
+
# resolve_friendly_id_conflict(['12345'])
|
315
|
+
# # => '123-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
316
|
+
#
|
317
|
+
# candidates - the Array with candidates.
|
318
|
+
#
|
319
|
+
# Returns the String with new slug.
|
302
320
|
def resolve_friendly_id_conflict(candidates)
|
303
|
-
|
321
|
+
uuid = SecureRandom.uuid
|
322
|
+
[
|
323
|
+
apply_slug_limit(candidates.first, uuid),
|
324
|
+
uuid
|
325
|
+
].compact.join(friendly_id_config.sequence_separator)
|
304
326
|
end
|
305
327
|
|
328
|
+
# Private: Apply slug limit to candidate.
|
329
|
+
#
|
330
|
+
# candidate - the String with candidate.
|
331
|
+
# uuid - the String with UUID.
|
332
|
+
#
|
333
|
+
# Return the String with truncated candidate.
|
334
|
+
def apply_slug_limit(candidate, uuid)
|
335
|
+
return candidate unless candidate && friendly_id_config.slug_limit
|
336
|
+
|
337
|
+
candidate[0...candidate_limit(uuid)]
|
338
|
+
end
|
339
|
+
private :apply_slug_limit
|
340
|
+
|
341
|
+
# Private: Get max length of candidate.
|
342
|
+
#
|
343
|
+
# uuid - the String with UUID.
|
344
|
+
#
|
345
|
+
# Returns the Integer with max length.
|
346
|
+
def candidate_limit(uuid)
|
347
|
+
[
|
348
|
+
friendly_id_config.slug_limit - uuid.size - friendly_id_config.sequence_separator.size,
|
349
|
+
0
|
350
|
+
].max
|
351
|
+
end
|
352
|
+
private :candidate_limit
|
353
|
+
|
306
354
|
# Sets the slug.
|
307
355
|
def set_slug(normalized_slug = nil)
|
308
356
|
if should_generate_new_friendly_id?
|
@@ -334,11 +382,11 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
334
382
|
end
|
335
383
|
private :unset_slug_if_invalid
|
336
384
|
|
337
|
-
# This module adds the `:slug_column`, and `:
|
338
|
-
# `:slug_generator_class` configuration options to
|
385
|
+
# This module adds the `:slug_column`, and `:slug_limit`, and `:sequence_separator`,
|
386
|
+
# and `:slug_generator_class` configuration options to
|
339
387
|
# {FriendlyId::Configuration FriendlyId::Configuration}.
|
340
388
|
module Configuration
|
341
|
-
attr_writer :slug_column, :sequence_separator
|
389
|
+
attr_writer :slug_column, :slug_limit, :sequence_separator
|
342
390
|
attr_accessor :slug_generator_class
|
343
391
|
|
344
392
|
# Makes FriendlyId use the slug column for querying.
|
@@ -361,6 +409,11 @@ Github issue](https://github.com/norman/friendly_id/issues/185) for discussion.
|
|
361
409
|
def slug_column
|
362
410
|
@slug_column ||= defaults[:slug_column]
|
363
411
|
end
|
412
|
+
|
413
|
+
# The limit that will be used for slug.
|
414
|
+
def slug_limit
|
415
|
+
@slug_limit ||= defaults[:slug_limit]
|
416
|
+
end
|
364
417
|
end
|
365
418
|
end
|
366
419
|
end
|
data/lib/friendly_id/version.rb
CHANGED
data/test/schema.rb
CHANGED
@@ -34,7 +34,7 @@ module FriendlyId
|
|
34
34
|
|
35
35
|
slugged_tables.each do |table_name|
|
36
36
|
add_column table_name, :slug, :string
|
37
|
-
add_index table_name, :slug, :unique => true
|
37
|
+
add_index table_name, :slug, :unique => true if 'novels' != table_name
|
38
38
|
end
|
39
39
|
|
40
40
|
scoped_tables.each do |table_name|
|
@@ -44,7 +44,6 @@ module FriendlyId
|
|
44
44
|
# This will be used to test scopes
|
45
45
|
add_column :novels, :novelist_id, :integer
|
46
46
|
add_column :novels, :publisher_id, :integer
|
47
|
-
remove_index :novels, :slug
|
48
47
|
add_index :novels, [:slug, :publisher_id, :novelist_id], :unique => true
|
49
48
|
|
50
49
|
# This will be used to test column name quoting
|
data/test/slugged_test.rb
CHANGED
@@ -271,6 +271,31 @@ class SlugSeparatorTest < TestCaseClass
|
|
271
271
|
|
272
272
|
end
|
273
273
|
|
274
|
+
class SlugLimitTest < TestCaseClass
|
275
|
+
|
276
|
+
include FriendlyId::Test
|
277
|
+
|
278
|
+
class Journalist < ActiveRecord::Base
|
279
|
+
extend FriendlyId
|
280
|
+
friendly_id :name, :use => :slugged, :slug_limit => 40
|
281
|
+
end
|
282
|
+
|
283
|
+
def model_class
|
284
|
+
Journalist
|
285
|
+
end
|
286
|
+
|
287
|
+
test "should limit slug size" do
|
288
|
+
transaction do
|
289
|
+
m1 = model_class.create! :name => 'a' * 50
|
290
|
+
assert_equal m1.slug, 'a' * 40
|
291
|
+
m2 = model_class.create! :name => m1.name
|
292
|
+
m2.save!
|
293
|
+
# "aaa-<uid>"
|
294
|
+
assert_match(/\Aa{3}\-/, m2.slug)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
274
299
|
class DefaultScopeTest < TestCaseClass
|
275
300
|
|
276
301
|
include FriendlyId::Test
|
@@ -424,4 +449,4 @@ class ConfigurableRoutesTest < TestCaseClass
|
|
424
449
|
assert_equal novel.id.to_s, novel.to_param
|
425
450
|
end
|
426
451
|
end
|
427
|
-
end
|
452
|
+
end
|
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.2.
|
4
|
+
version: 5.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
version: '0'
|
226
226
|
requirements: []
|
227
227
|
rubyforge_project: friendly_id
|
228
|
-
rubygems_version: 2.
|
228
|
+
rubygems_version: 2.6.13
|
229
229
|
signing_key:
|
230
230
|
specification_version: 4
|
231
231
|
summary: A comprehensive slugging and pretty-URL plugin.
|