Class: FriendlyId::SlugGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_id/slug_generator.rb

Overview

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

Instance Method Summary (collapse)

Constructor Details

- (SlugGenerator) initialize(scope)

Returns a new instance of SlugGenerator



6
7
8
# File 'lib/friendly_id/slug_generator.rb', line 6

def initialize(scope)
  @scope = scope
end

Instance Method Details

- (Boolean) available?(slug)

Returns:

  • (Boolean)


10
11
12
# File 'lib/friendly_id/slug_generator.rb', line 10

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

- (Object) generate(candidates)



14
15
16
17
# File 'lib/friendly_id/slug_generator.rb', line 14

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