slugs 1.2.5 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +3 -6
- data/lib/slugs/active_record/base.rb +11 -2
- data/lib/slugs/active_record/finders.rb +24 -0
- data/lib/slugs/active_record/non_translatable.rb +8 -4
- data/lib/slugs/active_record/translatable.rb +1 -1
- data/lib/slugs/railtie.rb +0 -1
- data/lib/slugs/version.rb +1 -1
- data/lib/slugs.rb +1 -1
- data/test/dummy/config/environments/production.rb +5 -1
- data/test/dummy/config/environments/test.rb +9 -1
- data/test/dummy/log/test.log +5131 -0
- data/test/records_test.rb +8 -8
- metadata +14 -8
- data/lib/slugs/active_record/relation.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aecbeea315d4b4db2d895b00469e2a38182fdd6a
|
4
|
+
data.tar.gz: 70ba94e82740be45d7e55ee9d1446fafc5cd06b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ee46e927cab1a0caaafb8f3d50f9b849d9967a8e021aa433eea986df07380cfac89126b786976a210079f02a2d7f3e0f898d6885d35d73dc117f9322bbaeb86
|
7
|
+
data.tar.gz: 566f8b8a896fd6bc4741e698c03b59149aee1eba08638159e57db08c7e580e9a9cf4d22a276de8003fdc063e6e7aa36ee57d7e8b0facae64d66f5638ef5bf067
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -49,15 +49,12 @@ If you need a very custom slug you can use a lambda, proc or block:
|
|
49
49
|
has_slug proc { |record| "#{record.prop}-custom" }
|
50
50
|
```
|
51
51
|
|
52
|
-
|
52
|
+
To find a record by slug:
|
53
53
|
```ruby
|
54
|
-
Model.find 'slug'
|
54
|
+
Model.slugged.find 'slug'
|
55
55
|
```
|
56
56
|
|
57
|
-
All the path and url helpers will start using the slug by default
|
58
|
-
```ruby
|
59
|
-
model_path(instance.id)
|
60
|
-
```
|
57
|
+
NOTE: All the path and url helpers will start using the slug by default.
|
61
58
|
|
62
59
|
## Credits
|
63
60
|
|
@@ -4,7 +4,15 @@ module Slugs
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def to_param
|
7
|
-
self.class.sluggable?
|
7
|
+
if self.class.sluggable?
|
8
|
+
if slug_changed?
|
9
|
+
slug_was
|
10
|
+
else
|
11
|
+
slug
|
12
|
+
end
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
8
16
|
end
|
9
17
|
|
10
18
|
protected
|
@@ -51,7 +59,7 @@ module Slugs
|
|
51
59
|
|
52
60
|
def has_slug(*args, &block)
|
53
61
|
unless sluggable?
|
54
|
-
if
|
62
|
+
if try(:translatable?)
|
55
63
|
include Slugs::ActiveRecord::Translatable
|
56
64
|
attr_translatable :slug
|
57
65
|
before_validation :generate_slugs
|
@@ -59,6 +67,7 @@ module Slugs
|
|
59
67
|
include Slugs::ActiveRecord::NonTranslatable
|
60
68
|
before_validation :generate_slug
|
61
69
|
end
|
70
|
+
include Slugs::ActiveRecord::Finders
|
62
71
|
if block_given?
|
63
72
|
self.slug = block
|
64
73
|
else
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Slugs
|
2
|
+
module ActiveRecord
|
3
|
+
module Finders
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def slugged
|
8
|
+
all.extending do
|
9
|
+
|
10
|
+
def find(*args)
|
11
|
+
find_by_slug args.first
|
12
|
+
end
|
13
|
+
|
14
|
+
def exists?(*args)
|
15
|
+
exists_by_slug? args.first
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -4,10 +4,6 @@ module Slugs
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
module ClassMethods
|
6
6
|
|
7
|
-
def exists_by_slug(id)
|
8
|
-
exists? slug: id
|
9
|
-
end
|
10
|
-
|
11
7
|
def find_previous_slug(slug)
|
12
8
|
where(
|
13
9
|
'slug LIKE ? OR slug = ?', "#{slug}-%", slug
|
@@ -16,6 +12,14 @@ module Slugs
|
|
16
12
|
).map(&:slug).select{ |r| r =~ /^#{slug}(-\d+)?$/ }.first
|
17
13
|
end
|
18
14
|
|
15
|
+
def find_by_slug(id)
|
16
|
+
find_by slug: id
|
17
|
+
end
|
18
|
+
|
19
|
+
def exists_by_slug?(id)
|
20
|
+
exists? slug: id
|
21
|
+
end
|
22
|
+
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
data/lib/slugs/railtie.rb
CHANGED
data/lib/slugs/version.rb
CHANGED
data/lib/slugs.rb
CHANGED
@@ -20,7 +20,11 @@ Dummy::Application.configure do
|
|
20
20
|
# config.action_dispatch.rack_cache = true
|
21
21
|
|
22
22
|
# Disable Rails's static asset server (Apache or nginx will already do this).
|
23
|
-
|
23
|
+
if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
|
24
|
+
config.serve_static_files = false
|
25
|
+
else
|
26
|
+
config.serve_static_assets = false
|
27
|
+
end
|
24
28
|
|
25
29
|
# Compress JavaScripts and CSS.
|
26
30
|
config.assets.js_compressor = :uglifier
|
@@ -13,7 +13,11 @@ Dummy::Application.configure do
|
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
15
|
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
-
|
16
|
+
if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
|
17
|
+
config.serve_static_files = false
|
18
|
+
else
|
19
|
+
config.serve_static_assets = false
|
20
|
+
end
|
17
21
|
config.static_cache_control = "public, max-age=3600"
|
18
22
|
|
19
23
|
# Show full error reports and disable caching.
|
@@ -33,4 +37,8 @@ Dummy::Application.configure do
|
|
33
37
|
|
34
38
|
# Print deprecation notices to the stderr.
|
35
39
|
config.active_support.deprecation = :stderr
|
40
|
+
|
41
|
+
if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
|
42
|
+
config.active_support.test_order = :random
|
43
|
+
end
|
36
44
|
end
|