Module: SpeakingId::InstanceMethods

Defined in:
lib/speaking_id/speaking_id.rb

Instance Method Summary collapse

Instance Method Details

#create_random_slugObject



51
52
53
54
55
# File 'lib/speaking_id/speaking_id.rb', line 51

def create_random_slug
  begin
    self[self.slug_column] = create_random_token
  end while slug_taken?
end

#create_slugObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/speaking_id/speaking_id.rb', line 37

def create_slug
  # Only creates a slug when the Active Record object is unsaved or got changed.
  return unless self.instance_eval("#{self.slug_source}_changed?")

  begin
    # Normalizes the slug source column or creates a random slug when blank.
    self[self.slug_column] = self[self.slug_source].normalize
    return create_random_slug if self[self.slug_column].blank?
    
    self[self.slug_column] << ((counter ||= 1) == 1 ? nil : counter).to_s
    counter += 1
  end while slug_taken?
end

#to_paramObject



57
58
59
# File 'lib/speaking_id/speaking_id.rb', line 57

def to_param
  self[self.slug_column]
end