has_permalink 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. data/lib/has_permalink.rb +12 -2
  2. metadata +4 -4
data/lib/has_permalink.rb CHANGED
@@ -64,10 +64,20 @@ module HasPermalink
64
64
  # Autofix duplication of permalinks
65
65
  def fix_duplication(permalink)
66
66
  if auto_fix_duplication
67
- n = self.class.where(["permalink LIKE ?", "#{permalink}%"]).count
67
+ n = self.class.where(["permalink = ?", permalink]).count
68
68
 
69
69
  if n > 0
70
- resolve_duplication(permalink, n)
70
+ links = self.class.where(["permalink LIKE ?", "#{permalink}%"]).order("id")
71
+
72
+ number = 0
73
+
74
+ links.each_with_index do |link, index|
75
+ if link.permalink =~ /-\d?$/
76
+ new_number = link.permalink.match(/-(\d?)$/)[1].to_i
77
+ number = new_number if new_number > number
78
+ end
79
+ end
80
+ resolve_duplication(permalink, number + 1)
71
81
  else
72
82
  permalink
73
83
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_permalink
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ola Karlsson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-05 00:00:00 Z
18
+ date: 2011-10-31 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: