Sha256: bdfac57bdbda161b87524f5c8c0fdff3d1c6353f8917e75e60bac0344ffe5030
Contents?: true
Size: 653 Bytes
Versions: 3
Compression:
Stored size: 653 Bytes
Contents
require "slugr/version" require "string" module Slugr def self.included(base) base.extend(ClassMethods) def set_slug return if (streng = self.send(self.source).to_s).blank? return if only_set_slug_if_empty && self.send(self.target).present? self.send("#{self.target.to_s}=", streng.to_s.slug) end end module ClassMethods def slugify source, args={} class_attribute :source, :target, :only_set_slug_if_empty self.source, self.target = source, args[:as] ||= :slug self.only_set_slug_if_empty = args[:when].eql?(:changed) ? false : true before_validation :set_slug end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
slugr-1.1.2 | lib/slugr.rb |
slugr-1.1.1 | lib/slugr.rb |
slugr-1.1.0 | lib/slugr.rb |