module FriendlyId::Finders::Base

Attributes

ids[RW]

An array of ids; can be both friendly and unfriendly.

model_class[RW]

The model class being used to perform the query.

options[RW]

The ActiveRecord query options

scope[RW]

The FriendlyId scope

Public Class Methods

friendly?(id) click to toggle source

Is the id friendly or numeric? Not that the return value here is false if the id is definitely not friendly, and nil if it can not be determined. The return value will be:

  • true - if the id is definitely friendly (i.e., any string with non-numeric characters)

  • false - if the id is definitely unfriendly (i.e., an Integer, a model instance, etc.)

  • nil - if it can not be determined (i.e., a numeric string like “206”.)

@return [true, false, nil] @see unfriendly?

# File lib/friendly_id/finders.rb, line 16
def self.friendly?(id)
  if id.is_a?(Integer) or id.class.respond_to? :friendly_id_config
    return false
  elsif id.to_i.to_s != id.to_s
    return true
  else
    return nil
  end
end
new(ids, model_class, options={}) click to toggle source
# File lib/friendly_id/finders.rb, line 34
def initialize(ids, model_class, options={})
  self.ids = ids
  self.options = options
  self.model_class = model_class
  self.scope = options[:scope]
end
unfriendly?(id) click to toggle source

Is the id numeric? @return [true, false, nil] true if definitely unfriendly, false if

definitely friendly, else +nil+.

@see friendly?

# File lib/friendly_id/finders.rb, line 30
def self.unfriendly?(id)
  !friendly?(id) unless friendly?(id) == nil
end

Public Instance Methods

find() click to toggle source

Perform the find.

# File lib/friendly_id/finders.rb, line 58
def find
  raise NotImplementedError
end
method_missing(*args, &block) click to toggle source
# File lib/friendly_id/finders.rb, line 41
def method_missing(*args, &block)
  model_class.send(*args, &block)
end