slugreate 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/slugreate.rb +38 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 90078cc2328397fa2846e83877b9437123aba531
|
4
|
+
data.tar.gz: 574f3279ee65553acaa55bd3331cab0004ae51a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43092c550e9293b9812d6f5cb566e9aa4dab0848c2c5651bcf8dfdf77a3f1b313b384148e531ec902381ef67f47370a427ee60a05646754507d8241d82e107de
|
7
|
+
data.tar.gz: 7a9d806320913081c251893ca1bea3765deb4d9002e7eee43e0e7a2e1d8a7ccba74d81d2bca764ad6ee6b4fdda8f8660a9650be8b6c2ff7ef987286d611dacad
|
data/lib/slugreate.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Slugreate
|
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
|
+
self.slug = self.send(self.class.slug_column.to_sym).parameterize
|
11
|
+
cl = self.class.find_by(slug: self.slug)
|
12
|
+
count = 2
|
13
|
+
while cl && cl != self
|
14
|
+
self.slug = append_suffix(self.slug, count)
|
15
|
+
cl = self.class.find_by(slug: self.slug)
|
16
|
+
count += 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def append_suffix(str, count)
|
21
|
+
if str.split('-').last.to_i != 0
|
22
|
+
return str.split('-').slice(0...-1).join('-') + '-' + count.to_s
|
23
|
+
else
|
24
|
+
return str + "-" + count.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_param
|
29
|
+
self.slug
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
def slugable_column(col_name)
|
34
|
+
self.slug_column = col_name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slugreate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gustavo Varallo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A very simple way to create pretty and robust URLs
|
14
|
+
email: 7a0831de@opayq.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/slugreate.rb
|
20
|
+
homepage: http://github.com/guvarallo/slugreate-gem
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.4.1
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Create robust slugs
|
43
|
+
test_files: []
|
44
|
+
has_rdoc:
|