Class: FriendlyId::Configuration
- Inherits:
-
Object
- Object
- FriendlyId::Configuration
- Defined in:
- lib/friendly_id/configuration.rb
Overview
The configuration paramters passed to friendly_id
will be stored in this object.
Instance Attribute Summary collapse
-
#base ⇒ Object
The base column or method used by FriendlyId as the basis of a friendly id or slug.
-
#defaults ⇒ Object
readonly
The default configuration options.
-
#model_class ⇒ Object
The model class that this configuration belongs to.
Instance Method Summary collapse
-
#initialize(model_class, values = nil) ⇒ Configuration
constructor
A new instance of Configuration.
-
#query_field ⇒ Object
The column that FriendlyId will use to find the record when querying by friendly id.
- #set(values) ⇒ Object private
-
#use(*modules) ⇒ Object
Lets you specify the modules to use with FriendlyId.
Constructor Details
#initialize(model_class, values = nil) ⇒ Configuration
Returns a new instance of Configuration.
37 38 39 40 41 |
# File 'lib/friendly_id/configuration.rb', line 37 def initialize(model_class, values = nil) @model_class = model_class @defaults = {} set values end |
Instance Attribute Details
#base ⇒ Object
The base column or method used by FriendlyId as the basis of a friendly id or slug.
For models that don’t use FriendlyId::Slugged, the base is the column that is used as the FriendlyId directly. For models using FriendlyId::Slugged, the base is a column or method whose value is used as the basis of the slug.
For example, if you have a model representing blog posts and that uses slugs, you likely will want to use the “title” attribute as the base, and FriendlyId will take care of transforming the human-readable title into something suitable for use in a URL.
28 29 30 |
# File 'lib/friendly_id/configuration.rb', line 28 def base @base end |
#defaults ⇒ Object (readonly)
The default configuration options.
31 32 33 |
# File 'lib/friendly_id/configuration.rb', line 31 def defaults @defaults end |
#model_class ⇒ Object
The model class that this configuration belongs to.
35 36 37 |
# File 'lib/friendly_id/configuration.rb', line 35 def model_class @model_class end |
Instance Method Details
#query_field ⇒ Object
The column that FriendlyId will use to find the record when querying by friendly id.
This method is generally only used internally by FriendlyId.
70 71 72 |
# File 'lib/friendly_id/configuration.rb', line 70 def query_field base.to_s end |
#set(values) ⇒ Object (private)
76 77 78 |
# File 'lib/friendly_id/configuration.rb', line 76 def set(values) values and values.each {|name, value| self.send "#{name}=", value} end |
#use(*modules) ⇒ Object
Lets you specify the modules to use with FriendlyId.
This method is invoked by friendly_id when passing the :use
option, or when using friendly_id with a block.
58 59 60 61 62 63 |
# File 'lib/friendly_id/configuration.rb', line 58 def use(*modules) modules.to_a.flatten.compact.map do |object| mod = object.kind_of?(Module) ? object : FriendlyId.const_get(object.to_s.classify) model_class.send(:include, mod) end end |