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
Strip diacritics from Western characters.
Locale-type options for ASCII approximations. These can be any of the values supported by {SlugString#approximate_ascii!}.
The method or column that will be used as the basis of the friendly_id string.
The class that's using the configuration.
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.
The method or column that will be used as the basis of the friendly_id string.
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`.
The message shown when a reserved word is used. @see reserved_words
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.
The method or relation to use as the friendly_id's scope.
The string that separates slug names from slug sequences. Defaults to “–”.
Strip non-ASCII characters from the friendly_id string.
Use slugs for storing the friendly_id string.
Use slugs for storing the friendly_id string.
Public Class Methods
# 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
# 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
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
# File lib/friendly_id/configuration.rb, line 98 def reserved?(word) reserved_words.include? word.to_s end
# File lib/friendly_id/configuration.rb, line 102 def reserved_error_message(word) [method, reserved_message % word] if reserved? word end
# File lib/friendly_id/configuration.rb, line 94 def reserved_words=(*words) @reserved_words = words.flatten.uniq end
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