Permalink
Browse files

Merge pull request #243 from leehambley/master

Related to Issue #200, slight code clean-up.
  • Loading branch information...
norman committed Feb 27, 2012
2 parents 76767e8 + d708cd0 commit 9ca0cf294e5384bbca252167d276e1315517b650
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/friendly_id/slug_generator.rb
@@ -12,10 +12,7 @@ def initialize(sluggable, normalized)
# Given a slug, get the next available slug in the sequence.
def next
# Don't assume that the separator is unique within the slug
sequence = conflict.to_param.gsub(/^#{Regexp.quote(normalized)}(#{Regexp.quote(separator)})?/, '').to_i
next_sequence = sequence == 0 ? 2 : sequence.next
"#{normalized}#{separator}#{next_sequence}"
"#{normalized}#{separator}#{next_in_sequence}"
end
# Generate a new sequenced slug.
@@ -25,6 +22,15 @@ def generate
private
def next_in_sequence
last_in_sequence == 0 ? 2 : last_in_sequence.next
end
def last_in_sequence
# Don't assume that the separator is unique in the slug.
@_last_in_sequence ||= conflict.to_param.gsub(/^#{Regexp.quote(normalized)}(#{Regexp.quote(separator)})?/, '').to_i
end
def column
sluggable.connection.quote_column_name friendly_id_config.slug_column
end

0 comments on commit 9ca0cf2

Please sign in to comment.