sluggable_jun 0.0.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 +7 -0
- data/lib/sluggable_jun.rb +30 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f051f9ba271625fe2e5954614ef699c3c2e4bdc7
|
|
4
|
+
data.tar.gz: e36373635be5be05c0c3dfbb654c413841ee23a5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: dcd6725aceb345e676fb8c061fa2a0ccf1df79a12eb27ca8758523c3588712bcb2caa95a7a6f6bb28d8bbffd5dc8c029d1e164543b73ae977c01e78e5dc90e08
|
|
7
|
+
data.tar.gz: 2a0698b2b74e39e9bc58e35342dda2a9ad97380c3a8d3ffba5eb31c89f1b31171bdb98b385eaa59f7588a0d236cde451ecb4baa7055c3ae6fb108c2a0e92e37d
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module SluggableJun
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
included do
|
|
5
|
+
before_save :generate_slug!
|
|
6
|
+
class_attribute :slug_column
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def generate_slug!
|
|
10
|
+
a_slug = self[slug_column].parameterize
|
|
11
|
+
|
|
12
|
+
return if self.slug && self.slug[/\w+/]== a_slug
|
|
13
|
+
slug_copies = self.class.where("slug LIKE :prefix",prefix: "#{a_slug}%").size
|
|
14
|
+
if slug_copies.zero? || slug_copies == 1 && self.slug
|
|
15
|
+
self.slug = a_slug
|
|
16
|
+
else
|
|
17
|
+
self.slug = "#{a_slug}-#{slug_copies + 1}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_param
|
|
22
|
+
slug
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module ClassMethods
|
|
26
|
+
def sluggable_column(column_name)
|
|
27
|
+
self.slug_column = column_name
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sluggable_jun
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tyler Lippert(Reltre)
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-06-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: |-
|
|
14
|
+
This gem allow you to implement slugging for your models
|
|
15
|
+
in a rails project, just 'require' this gem and include it in the model file.
|
|
16
|
+
email: tglippert@gmail.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- lib/sluggable_jun.rb
|
|
22
|
+
homepage: http://github.com
|
|
23
|
+
licenses: []
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.4.8
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: A gem that enables slugging in project
|
|
45
|
+
test_files: []
|
|
46
|
+
has_rdoc:
|