Sha256: d91a47dbf15daa8dae98d52b7c2e97b9700b90c185a0ce71e3db521c2b17754f

Contents?: true

Size: 476 Bytes

Versions: 7

Compression:

Stored size: 476 Bytes

Contents

module FriendlyId
  # The default slug generator offers functionality to check slug strings for
  # uniqueness and, if necessary, appends a sequence to guarantee it.
  class SlugGenerator

    def initialize(scope)
      @scope = scope
    end

    def available?(slug)
      !@scope.exists_by_friendly_id?(slug)
    end

    def add(slug)
      slug
    end

    def generate(candidates)
      candidates.each {|c| return add c if available?(c)}
      nil
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
friendly_id-5.0.4 lib/friendly_id/slug_generator.rb
friendly_id-5.0.3 lib/friendly_id/slug_generator.rb
friendly_id-5.0.2 lib/friendly_id/slug_generator.rb
friendly_id-5.0.1 lib/friendly_id/slug_generator.rb
friendly_id-5.0.0 lib/friendly_id/slug_generator.rb
friendly_id-5.0.0.rc3 lib/friendly_id/slug_generator.rb
friendly_id-5.0.0.rc2 lib/friendly_id/slug_generator.rb