Module: FriendlyId::Finders::Base

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idsObject

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



47
48
49
# File 'lib/friendly_id/finders.rb', line 47

def ids
  @ids
end

#model_classObject

The model class being used to perform the query.



56
57
58
# File 'lib/friendly_id/finders.rb', line 56

def model_class
  @model_class
end

#optionsObject

The ActiveRecord query options



50
51
52
# File 'lib/friendly_id/finders.rb', line 50

def options
  @options
end

#scopeObject

The FriendlyId scope



53
54
55
# File 'lib/friendly_id/finders.rb', line 53

def scope
  @scope
end

Class Method Details

.friendly?(id) ⇒ true, ...

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”.)

Returns:

  • (true, false, nil)

See Also:

  • #unfriendly?


21
22
23
24
25
26
27
28
29
# File 'lib/friendly_id/finders.rb', line 21

def self.friendly?(id)
  if id.is_a?(Integer) or id.is_a?(Symbol) 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

.unfriendly?(id) ⇒ true, ...

Is the id numeric?

Returns:

  • (true, false, nil)

    true if definitely unfriendly, false if definitely friendly, else nil.

See Also:

  • #friendly?


35
36
37
# File 'lib/friendly_id/finders.rb', line 35

def self.unfriendly?(id)
  !friendly?(id) unless friendly?(id) == nil
end

Instance Method Details

#findObject

Perform the find.

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/friendly_id/finders.rb', line 59

def find
  raise NotImplementedError
end

#initialize(ids, model_class, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/friendly_id/finders.rb', line 39

def initialize(ids, model_class, options={})
  self.ids = ids
  self.options = options
  self.model_class = model_class
  self.scope = options.delete :scope
end