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.
-
- (Object) modules
readonly
The modules in use.
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.
-
- (Boolean) uses?(modul)
Returns whether the given module is in use.
Constructor Details
- (Configuration) initialize(model_class, values = nil)
A new instance of Configuration
40 41 42 43 44 45 |
# File 'lib/friendly_id/configuration.rb', line 40 def initialize(model_class, values = nil) @model_class = model_class @defaults = {} @modules = [] 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.
38 39 40 |
# File 'lib/friendly_id/configuration.rb', line 38 def model_class @model_class end |
- (Object) modules (readonly)
The modules in use
34 35 36 |
# File 'lib/friendly_id/configuration.rb', line 34 def modules @modules 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.
80 81 82 |
# File 'lib/friendly_id/configuration.rb', line 80 def query_field base.to_s end |
- (Object) set(values) (private)
86 87 88 |
# File 'lib/friendly_id/configuration.rb', line 86 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.
62 63 64 65 66 67 68 |
# File 'lib/friendly_id/configuration.rb', line 62 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) @modules << mod.name.split("::").last.downcase.to_sym if mod.name.present? end end |
- (Boolean) uses?(modul)
Returns whether the given module is in use
71 72 73 |
# File 'lib/friendly_id/configuration.rb', line 71 def uses?(modul) @modules.include?(modul) end |