gastropod 0.1.0 → 0.2.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.
- data/README.md +3 -1
- data/lib/gastropod.rb +7 -6
- data/lib/gastropod/version.rb +1 -1
- data/spec/db/activerecord.db +0 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Simple library for generating slugs
|
4
4
|
|
5
|
+

|
6
|
+
|
5
7
|

|
6
8
|
|
7
9
|
## Install
|
@@ -43,7 +45,7 @@ Simple library for generating slugs
|
|
43
45
|
|
44
46
|
## Customisation
|
45
47
|
|
46
|
-
|
48
|
+
Override the instance method 'slug_finder' for custom scoping
|
47
49
|
|
48
50
|
## Contributing
|
49
51
|
|
data/lib/gastropod.rb
CHANGED
@@ -14,10 +14,6 @@ module Gastropod
|
|
14
14
|
@slug_source_attribute
|
15
15
|
end
|
16
16
|
|
17
|
-
def slug_finder
|
18
|
-
instance_variable_defined?("@slug_finder") ? @slug_finder : default_slug_finder
|
19
|
-
end
|
20
|
-
|
21
17
|
def default_slug_finder
|
22
18
|
lambda {|value| where(:slug => value) }
|
23
19
|
end
|
@@ -30,6 +26,10 @@ module Gastropod
|
|
30
26
|
|
31
27
|
private
|
32
28
|
|
29
|
+
def slug_finder
|
30
|
+
self.class.default_slug_finder
|
31
|
+
end
|
32
|
+
|
33
33
|
def slug_source
|
34
34
|
send self.class.slug_source_attribute
|
35
35
|
end
|
@@ -46,10 +46,11 @@ module Gastropod
|
|
46
46
|
possible_slug = slug_from_source
|
47
47
|
|
48
48
|
index = 2
|
49
|
-
while
|
49
|
+
while slug_finder.call(possible_slug).any?
|
50
50
|
possible_slug = slug_from_source + "-#{index}"
|
51
|
-
index+= 1
|
51
|
+
index += 1
|
52
52
|
end
|
53
|
+
|
53
54
|
possible_slug
|
54
55
|
end
|
55
56
|
end
|
data/lib/gastropod/version.rb
CHANGED
data/spec/db/activerecord.db
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gastropod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-03-
|
13
|
+
date: 2013-03-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|