Sha256: 9bc9a380b324886f45024cc831093d105a1db072898e895b845d4448be968bf2

Contents?: true

Size: 588 Bytes

Versions: 27

Compression:

Stored size: 588 Bytes

Contents

module MinimumViableProduct
  module Slugification
    extend ActiveSupport::Concern

    module ClassMethods
      def slugify(name, opts={})
        _opts = opts.reverse_merge(:if => lambda{ |obj| obj.send("#{name}_changed?".to_sym) })
        before_validation -> {
          self.slug = slugify(self.send(name.to_sym))
          self.slug += SecureRandom.uuid if self.class.find_by(slug: self.slug).present?
        }, _opts
      end
    end

    private

    def slugify(str)
      str.gsub(/[^a-zA-Z0-9]+/,'-')
         .gsub(/^[-]+|[-]+$/,'')
         .downcase
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
minimum_viable_product-0.7.9 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.8 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.7 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.6 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.5 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.4 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.3 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.2 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.1 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.7.0 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.6.7 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.6.6 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.6.5 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.6.4 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.6.3 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.6.2 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.6.1 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.6.0 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.5.7 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.5.6 app/models/concerns/minimum_viable_product/slugification.rb