Module: FriendlyId::Finders::Base
- Extended by:
- Forwardable
- Included in:
- ActiveRecordAdapter::Finders::Multiple, ActiveRecordAdapter::SimpleModel::SingleFinder, ActiveRecordAdapter::SluggedModel::SingleFinder
- Defined in:
- lib/friendly_id/finders.rb
Instance Attribute Summary collapse
-
#ids ⇒ Object
readonly
An array of ids; can be both friendly and unfriendly.
-
#model_class ⇒ Object
The model class being used to perform the query.
-
#options ⇒ Object
The ActiveRecord query options.
-
#scope ⇒ Object
readonly
The FriendlyId scope.
Class Method Summary collapse
-
.friendly?(id) ⇒ true, ...
Is the id friendly or numeric? Not that the return value here is
false
if theid
is definitely not friendly, andnil
if it can not be determined. -
.unfriendly?(id) ⇒ true, ...
Is the id numeric?.
Instance Method Summary collapse
-
#find ⇒ Object
Perform the find.
- #initialize(ids, model_class, options = {}) ⇒ Object
Instance Attribute Details
#ids ⇒ Object
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_class ⇒ Object
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 |
#options ⇒ Object
The ActiveRecord query options
50 51 52 |
# File 'lib/friendly_id/finders.rb', line 50 def @options end |
#scope ⇒ Object
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”.)
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?
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
#find ⇒ Object
Perform the find.
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, ={}) self.ids = ids self. = self.model_class = model_class self.scope = .delete :scope end |