class FriendlyId::Configuration

This class is not intended to be used on its own, it is used internally by `has_friendly_id` to store a model's configuration and configuration-related methods.

The arguments accepted by has_friendly_id correspond to the writeable instance attributes of this class; please see the description of the attributes below for information on the possible options.

@example has_friendly_id :name,

:use_slug => true,
:max_length => 150,
:approximate_ascii => true,
:ascii_approximation_options => :german,
:sequence_separator => ":",
:reserved_words => ["reserved", "words"],
:scope => :country,
:cache_column => :my_cache_column_name
# etc.

Constants

DEFAULTS

Attributes

approximate_ascii[RW]

Strip diacritics from Western characters.

ascii_approximation_options[RW]

Locale-type options for ASCII approximations. These can be any of the values supported by {SlugString#approximate_ascii!}.

column[R]

The method or column that will be used as the basis of the friendly_id string.

configured_class[R]

The class that's using the configuration.

max_length[RW]

The maximum allowed length for a friendly_id string. This is checked after a string is processed by FriendlyId to remove spaces, special characters, etc.

method[R]

The method or column that will be used as the basis of the friendly_id string.

normalizer[RW]

A block or proc through which to filter the friendly_id text. This method will be removed from FriendlyId 3.0. @deprecated Please override the normalize_friendly_id

method in your model class rather than passing a block to %xhas_friendly_id`.
reserved_message[RW]

The message shown when a reserved word is used. @see reserved_words

reserved_words[RW]

Array of words that are reserved and can't be used as friendly_id strings. If a listed word is used in a sluggable model, it will raise a FriendlyId::SlugGenerationError. For Rails applications, you are recommended to include “index” and “new”, which used as the defaults unless overridden.

scope[RW]

The method or relation to use as the friendly_id's scope.

sequence_separator[RW]

The string that separates slug names from slug sequences. Defaults to “–”.

strip_non_ascii[RW]

Strip non-ASCII characters from the friendly_id string.

use_slug[RW]

Use slugs for storing the friendly_id string.

use_slugs=[RW]

Use slugs for storing the friendly_id string.

Public Class Methods

new(configured_class, method, options = nil) { |self| ... } click to toggle source
# File lib/friendly_id/configuration.rb, line 79
def initialize(configured_class, method, options = nil, &block)
  @configured_class = configured_class
  @method = method.to_sym
  DEFAULTS.merge(options || {}).each do |key, value|
    self.send "#{key}=".to_sym, value
  end
  yield self if block_given?
end

Public Instance Methods

normalizer=(arg) click to toggle source
# File lib/friendly_id/configuration.rb, line 88
def normalizer=(arg)
  return if arg.nil?
  warn("passing a block to has_friendly_id is deprecated and will be removed from 3.0. Please override #normalize_friendly_id.")
  @normalizer = arg
end
reserved=(*args) click to toggle source

This method will be removed from FriendlyId 3.0. @deprecated Please use {#reserved_words #reserved_words}.

# File lib/friendly_id/configuration.rb, line 108
def reserved=(*args)
  warn('The "reserved" option is deprecated and will be removed from FriendlyId 3.0. Please use "reserved_words".')
  self.reserved_words = *args
end
reserved?(word) click to toggle source
# File lib/friendly_id/configuration.rb, line 98
def reserved?(word)
  reserved_words.include? word.to_s
end
reserved_error_message(word) click to toggle source
# File lib/friendly_id/configuration.rb, line 102
def reserved_error_message(word)
  [method, reserved_message % word] if reserved? word
end
reserved_words=(*words) click to toggle source
# File lib/friendly_id/configuration.rb, line 94
def reserved_words=(*words)
  @reserved_words = words.flatten.uniq
end
strip_diacritics=(*args) click to toggle source

This method will be removed from FriendlyId 3.0. @deprecated Please use {#approximate_ascii #approximate_ascii}.

# File lib/friendly_id/configuration.rb, line 115
def strip_diacritics=(*args)
  warn('strip_diacritics is deprecated and will be removed from 3.0. Please use #approximate_ascii')
  self.approximate_ascii = *args
end