Sha256: 2cb84807599def590f0d454d120bd5cf0d2565a0c17585120d01f3e520f70706

Contents?: true

Size: 544 Bytes

Versions: 6

Compression:

Stored size: 544 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(/\s/,'_').dasherize.downcase
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
minimum_viable_product-0.3.3 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.3.2 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.3.1 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.3.0 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.2.7 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.2.6 app/models/concerns/minimum_viable_product/slugification.rb