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)
-
- (Object) base
The base column or method used by FriendlyId as the basis of a friendly id or slug.
-
- (Object) defaults
readonly
The default configuration options.
-
- (Object) model_class
The model class that this configuration belongs to.
Instance Method Summary (collapse)
-
- (Configuration) initialize(model_class, values = nil)
constructor
A new instance of Configuration.
-
- (Object) query_field
The column that FriendlyId will use to find the record when querying by friendly id.
- - (Object) set(values) private
-
- (Object) use(*modules)
Lets you specify the modules to use with FriendlyId.
Constructor Details
- (Configuration) initialize(model_class, values = nil)
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
- (Object) base
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 |
- (Object) defaults (readonly)
The default configuration options.
31 32 33 |
# File 'lib/friendly_id/configuration.rb', line 31 def defaults @defaults end |
- (Object) model_class
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
- (Object) query_field
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 |
- (Object) set(values) (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 |
- (Object) use(*modules)
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 |