Module: Sequel::Plugins::Sluggable
- Defined in:
- lib/sequel_sluggable.rb,
lib/sequel_sluggable/version.rb
Overview
The Sluggable plugin creates hook that automatically sets ‘slug’ field to the slugged value of the column specified by :source option.
You need to have “target” column in your model.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, RSpecHelper
Constant Summary collapse
- DEFAULT_TARGET_COLUMN =
:slug- VERSION =
'0.0.6'.freeze
Class Method Summary collapse
-
.configure(model, opts = {}) ⇒ Object
Plugin configuration.
Class Method Details
.configure(model, opts = {}) ⇒ Object
Plugin configuration
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sequel_sluggable.rb', line 13 def self.configure(model, opts={}) model. = opts model..freeze model.class_eval do # Sets the slug to the normalized URL friendly string # # Compute slug for the value # # @param [String] String to be slugged # @return [String] define_method("#{[:target]}=") do |value| sluggator = self.class.[:sluggator] slug = sluggator.call(value, self) if sluggator.respond_to?(:call) slug ||= self.send(sluggator, value) if sluggator slug ||= to_slug(value) super(slug) end end end |