Class: FriendlyId::SlugGenerator
- Inherits:
-
Object
- Object
- FriendlyId::SlugGenerator
- 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)
- - (Boolean) available?(slug)
- - (Object) generate(candidates)
-
- (SlugGenerator) initialize(scope)
constructor
A new instance of SlugGenerator.
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)
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 |