Module: SluggableFinder::Finder

Defined in:
lib/sluggable_finder/finder.rb

Overview

This module is included by the base class as well as AR asociation collections

Instance Method Summary collapse

Instance Method Details

#find_sluggable(opts, *args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sluggable_finder/finder.rb', line 5

def find_sluggable(opts,*args)
  key = args.first
  if key.is_a?(String) and not (opts[:allow_numerical] == false and key =~ /\A\d+\Z/)
    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
    find_without_slug(*args)
  end
end