Skip to content

Commit

Permalink
Document method's intent a little better
Browse files Browse the repository at this point in the history
This is in anticipation of cleaning up this method
  • Loading branch information
norman committed Mar 14, 2012
1 parent 325cb33 commit e211c19
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/friendly_id/slugged.rb
Expand Up @@ -252,10 +252,17 @@ def normalize_friendly_id(value)
def should_generate_new_friendly_id?
base = send(friendly_id_config.base)
slug_value = send(friendly_id_config.slug_column)

# If the slug base is nil, and the slug field is nil, then we're going to
# leave the slug column NULL.
return false if base.nil? && slug_value.nil?
# Otherwise, if this is a new record, we're definitely going to try to
# create a new slug.
return true if new_record?
slug_base = normalize_friendly_id(base)
separator = Regexp.escape friendly_id_config.sequence_separator
# If the slug base (without sequence) is different from either the current
# friendly id or the slug value, then we'll generate a new friendly_id.
slug_base != (current_friendly_id || slug_value).try(:sub, /#{separator}[\d]*\z/, '')
end

Expand Down

0 comments on commit e211c19

Please sign in to comment.