Module: Pseudocephalopod::Finders

Defined in:
lib/pseudocephalopod/finders.rb

Instance Method Summary collapse

Instance Method Details

#find_using_slug(slug, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/pseudocephalopod/finders.rb', line 4

def find_using_slug(slug, options = {})
  slug = slug.to_s
  value = nil
  value ||= find_by_id(slug.to_i, options) if slug =~ /\A\d+\Z/
  value ||= with_cached_slug(slug).first(options)
  value ||= find_using_slug_history(slug, options) if use_slug_history
  value.found_via_slug = slug if value.present?
  value
end

#find_using_slug!(slug, options = {}) ⇒ Object



14
15
16
# File 'lib/pseudocephalopod/finders.rb', line 14

def find_using_slug!(slug, options = {})
  find_using_slug(slug, options) or raise ActiveRecord::RecordNotFound
end