Sha256: de51ce092afaa590be29e88f61a97a8eac15a19eaf22d70c4ca2feb86ad8dcb9

Contents?: true

Size: 379 Bytes

Versions: 21

Compression:

Stored size: 379 Bytes

Contents

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)) }, _opts
    end
  end

  private

  def slugify(str)
    str.gsub(/\s/,'_').dasherize.downcase
  end
end

Version data entries

21 entries across 20 versions & 2 rubygems

Version Path
minimum_viable_product-0.0.23 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.22 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.21 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.20 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.19 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.18 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.17 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.16 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.15 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.14 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.13 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.11 app/models/concerns/minimum_viable_product/slugification.rb
minimum_viable_product-0.0.11 test/dummy/node_modules/minimum_viable_product/app/models/concerns/slugification.rb
minimum_viable_product-0.0.10 app/models/concerns/slugification.rb
minimum_viable_product-0.0.9 app/models/concerns/slugification.rb
minimum_viable_product-0.0.8 app/models/concerns/slugification.rb
minimum-viable-product-0.0.7 app/models/concerns/slugification.rb
minimum-viable-product-0.0.6 app/models/concerns/slugification.rb
minimum-viable-product-0.0.5 app/models/concerns/slugification.rb
minimum-viable-product-0.0.4 app/models/concerns/slugification.rb