module Arkaan::Concerns::Sluggable::ClassMethods

Module holding the class methods for the classes including this concern. @author Vincent Courtois <courtois.vincent@outlook.com>

Public Instance Methods

make_sluggable() click to toggle source

Add the field and its validations in the model including it.

# File lib/arkaan/concerns/sluggable.rb, line 14
def make_sluggable
  # @!attribute [rw] slug
  #   @return [String] the slug of the current entity, in snake-case.
  field :slug, type: String

  validates :slug,
            length: { minimum: 4, message: 'minlength', if: :slug? },
            format: { with: /\A[a-z]+(_[a-z]+)*\z/, message: 'pattern', if: :slug? },
            uniqueness: { message: 'uniq', if: :slug? },
            presence: { message: 'required' }
end