lib/sluggable_finder/orm.rb in sluggable_finder-2.3.2 vs lib/sluggable_finder/orm.rb in sluggable_finder-2.3.3
- old
+ new
@@ -1,11 +1,11 @@
module SluggableFinder
module Orm
module ClassMethods
- def sluggable_finder(field = :title, options = {})
+ def sluggable_finder(field = :title, options = {}, &slug_modifier)
return if self.included_modules.include?(SluggableFinder::Orm::InstanceMethods)
extend SluggableFinder::Finder
extend SluggableFinder::BaseFinder
include SluggableFinder::Orm::InstanceMethods
@@ -19,10 +19,11 @@
:scope => nil,
:to => :slug,
:reserved_slugs => [],
:allow_integer_ids => true,
:upcase => false,
+ :slug_modifier => slug_modifier || nil,
:ignore_sti => false # if true, Uniqueness won't check sibling classes.
}.merge( options ))
class_inheritable_reader :sluggable_finder_options
if sluggable_finder_options[:scope]
@@ -74,9 +75,10 @@
write_attribute(destination_column, s)
end
def get_value_or_generate_random(column_name)
v = self.send(column_name)
+ v = sluggable_finder_options[:slug_modifier].call(v) if sluggable_finder_options[:slug_modifier]
v || SluggableFinder.random_slug_for(self.class)
end
def create_sluggable_slug
suffix = ''
\ No newline at end of file