class FriendlyId::SlugGenerator

The default slug generator offers functionality to check slug candidates for availability.

Public Class Methods

new(scope) click to toggle source
# File lib/friendly_id/slug_generator.rb, line 6
def initialize(scope)
  @scope = scope
end

Public Instance Methods

available?(slug) click to toggle source
# File lib/friendly_id/slug_generator.rb, line 10
def available?(slug)
  !@scope.exists_by_friendly_id?(slug)
end
generate(candidates) click to toggle source
# File lib/friendly_id/slug_generator.rb, line 14
def generate(candidates)
  candidates.each {|c| return c if available?(c)}
  nil
end