Module: Sequel::Plugins::GenerateSlug

Defined in:
lib/sequel/plugins/generate_slug.rb

Overview

GenerateSlug plugin generates a unique slug based on the specified source and additional columns. The plugin is designed to work with the Sequel ORM.

Examples:

class Post < Sequel::Model
  plugin :generate_slug, column: 'slug', source: 'title', additional: 'identifier'
end

post = Post.create(title: 'Hello World', identifier: 'abcdef')
post.slug # => 'hello-world'

post = Post.create(title: 'Hello World', identifier: 'abcdef')
post.slug # => 'hello-world-abcdef'

post = Post.create(title: 'Hello World', identifier: 'abcdef')
post.slug # => 'hello-world-abcdef-1'

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.configure(model, opts = {}) ⇒ Object

Configure the plugin with the given options.

Parameters:

  • model (Sequel::Model)

    the model to configure the plugin for

  • opts (Hash) (defaults to: {})

    the options to configure the plugin with

Options Hash (opts):

  • :column (Symbol) — default: :slug

    the column to store the generated slug

  • :source (Symbol) — default: :title

    the source column to generate the slug from

  • :additional (Symbol) — default: :identifier

    the additional column to use in slug generation if necessary



32
33
34
35
36
37
38
# File 'lib/sequel/plugins/generate_slug.rb', line 32

def self.configure(model, opts = {})
  model.instance_exec do
    @slug_column = opts[:column] || :slug
    @source_column = opts[:source] || :title
    @additional_column = opts[:additional] || :identifier
  end
end