lib/sluggable_finder/finder.rb in sluggable_finder-2.1.1 vs lib/sluggable_finder/finder.rb in sluggable_finder-2.2.0

- old
+ new

@@ -2,28 +2,27 @@ # This module is included by the base class as well as AR asociation collections # module Finder def find_sluggable(opts,*args) key = args.first - if (key.is_a?(String) and !(key =~ /\A\d+\Z/))#only contain digits - options = {:conditions => ["#{ opts[:to]} = ?", key]} - error = "There is no #{opts[:sluggable_type]} with #{opts[:to]} '#{key}'" - with_scope(:find => options) do - find_without_slug(:first) or - raise SluggableFinder.not_found_exception.new(error) - end - else + if key.is_a?(Symbol) || (key.to_s =~ /\A\d+\Z/ && opts[:allow_integer_ids]) # normal INT find find_without_slug(*args) + else # sluggable find + options = {:conditions => ["#{ opts[:to]} = ?", key]} + error = "There is no #{opts[:sluggable_type]} with #{opts[:to]} '#{key}'" + with_scope(:find => options) do + find_without_slug(:first) or + raise SluggableFinder.not_found_exception.new(error) + end end end end module BaseFinder def find_with_slug(*args) return find_without_slug(*args) unless respond_to?(:sluggable_finder_options) - options = sluggable_finder_options - find_sluggable(options,*args) + find_sluggable(sluggable_finder_options,*args) end end module AssociationProxyFinder def find_with_slug(*args) \ No newline at end of file