Class: FriendlyId::ActiveRecordAdapter::Finders::Find

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/friendly_id/active_record_adapter/finders.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, id, options) ⇒ Find

Returns a new instance of Find.



19
20
21
22
23
24
25
26
27
# File 'lib/friendly_id/active_record_adapter/finders.rb', line 19

def initialize(klass, id, options)
  @klass     = klass
  @id        = id
  @options   = options
  if options[:scope]
    raise "The :scope finder option has been removed from FriendlyId 3.2.0 " +
      "https://github.com/norman/friendly_id/issues#issue/88"
  end
end

Instance Attribute Details

#friendly_idsObject (readonly)

Returns the value of attribute friendly_ids.



16
17
18
# File 'lib/friendly_id/active_record_adapter/finders.rb', line 16

def friendly_ids
  @friendly_ids
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/friendly_id/active_record_adapter/finders.rb', line 13

def id
  @id
end

#klassObject (readonly)

Returns the value of attribute klass.



12
13
14
# File 'lib/friendly_id/active_record_adapter/finders.rb', line 12

def klass
  @klass
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#resultObject (readonly)

Returns the value of attribute result.



15
16
17
# File 'lib/friendly_id/active_record_adapter/finders.rb', line 15

def result
  @result
end

#unfriendly_idsObject (readonly)

Returns the value of attribute unfriendly_ids.



17
18
19
# File 'lib/friendly_id/active_record_adapter/finders.rb', line 17

def unfriendly_ids
  @unfriendly_ids
end

Instance Method Details

#find_oneObject



29
30
31
32
33
34
# File 'lib/friendly_id/active_record_adapter/finders.rb', line 29

def find_one
  return find_one_with_cached_slug if !fc.scope? && cache_column?
  return find_one_with_slug if use_slugs?
  @result = scoped(:conditions => ["#{table_name}.#{fc.column} = ?", id]).first(options)
  assign_status
end

#find_someObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/friendly_id/active_record_adapter/finders.rb', line 36

def find_some
  parse_ids!
  scope = some_friendly_scope
  if use_slugs? && @friendly_ids.present?
    scope = scope.scoped(:joins => :slugs)
  end
  options[:readonly] = false unless options[:readonly]
  @result = scope.all(options).uniq
  validate_expected_size!
  @result.each { |record| record.friendly_id_status.name = id }
end