Sha256: 42245869d9eed56c0d5365944d9a95f197ef67764597138e7b09efd149c00c2f

Contents?: true

Size: 887 Bytes

Versions: 24

Compression:

Stored size: 887 Bytes

Contents

module ManualSlug::Mongoid
  extend ActiveSupport::Concern
  include ::Mongoid::Slug

  def text_slug
    self._slugs.blank? ? '' : self._slugs.last
  end
  def text_slug=(slug)
    if slug.blank?
      self._slugs = []
    else
      if self._slugs.blank?
        self._slugs = [slug]
      else
        self._slugs.delete(slug)
        self._slugs << slug
      end
    end
  end

  module ClassMethods
    def manual_slug(field, options = {}, callback = true)
      options.merge!(permanent: true, history: true)
      slug field, options

      # we will create slugs manually when needed
      skip_callback :create, :before, :build_slug

      before_validation do
        if self._slugs.blank?
          self.build_slug
        else
          self._slugs = self._slugs.map{ |s| s.strip }.select {|s| !s.blank? }
        end
        true
      end if callback
    end
  end

end


Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
manual_slug-0.1.0 lib/manual_slug/mongoid.rb
rocket_cms-0.21.1 lib/manual_slug/mongoid.rb
rocket_cms-0.21.0 lib/manual_slug/mongoid.rb
rocket_cms-0.20.1 lib/manual_slug/mongoid.rb
rocket_cms-0.20.0 lib/manual_slug/mongoid.rb
rocket_cms-0.19.8 lib/manual_slug/mongoid.rb
rocket_cms-0.19.7 lib/manual_slug/mongoid.rb
rocket_cms-0.19.6 lib/manual_slug/mongoid.rb
rocket_cms-0.19.4 lib/manual_slug/mongoid.rb
rocket_cms-0.19.3 lib/manual_slug/mongoid.rb
rocket_cms-0.19.2 lib/manual_slug/mongoid.rb
rocket_cms-0.19.1 lib/manual_slug/mongoid.rb
rocket_cms-0.19.0 lib/manual_slug/mongoid.rb
rocket_cms-0.18.5 lib/manual_slug/mongoid.rb
rocket_cms-0.18.4 lib/manual_slug/mongoid.rb
rocket_cms-0.18.3 lib/manual_slug/mongoid.rb
rocket_cms-0.18.2 lib/manual_slug/mongoid.rb
rocket_cms-0.18.1 lib/manual_slug/mongoid.rb
rocket_cms-0.18.0 lib/manual_slug/mongoid.rb
rocket_cms-0.17.2 lib/manual_slug/mongoid.rb