Module: ActiveRecord::Collections::Records

Included in:
ActiveRecord::Collection
Defined in:
lib/active_record/collections/records.rb

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/active_record/collections/records.rb', line 40

def each(&block)
  batch! if try(:should_batch?)

  if try(:batched?)
    flat_batch_map.each { |record| block_given? ? yield(record) : record }
  else
    records.each { |record| block_given? ? yield(record) : record }
  end
end

#flat_map(&block) ⇒ Object



60
61
62
# File 'lib/active_record/collections/records.rb', line 60

def flat_map(&block)
  map(&block).flatten
end

#lengthObject



36
37
38
# File 'lib/active_record/collections/records.rb', line 36

def length
  to_a.length
end

#map(&block) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/active_record/collections/records.rb', line 50

def map(&block)
  batch! if try(:should_batch?)

  if try(:batched?)
    flat_batch_map.map { |record| block_given? ? yield(record) : record }
  else
    each.map { |record| block_given? ? yield(record) : record }
  end
end

#pluck(col) ⇒ Object



12
13
14
# File 'lib/active_record/collections/records.rb', line 12

def pluck(col)
  relation.pluck(col)
end

#record_idsObject



8
9
10
# File 'lib/active_record/collections/records.rb', line 8

def record_ids
  @record_ids ||= records.loaded? ? records.map(&:id) : records.pluck(:id)
end

#recordsObject



4
5
6
# File 'lib/active_record/collections/records.rb', line 4

def records
  @records ||= relation
end

#sizeObject



32
33
34
# File 'lib/active_record/collections/records.rb', line 32

def size
  @size ||= relation.size
end

#to_aryObject Also known as: to_a



16
17
18
# File 'lib/active_record/collections/records.rb', line 16

def to_ary
  records.to_a
end

#total_countObject Also known as: total, count



25
26
27
28
# File 'lib/active_record/collections/records.rb', line 25

def total_count
  #batch! if try(:should_batch?)
  total_records
end

#total_recordsObject



21
22
23
# File 'lib/active_record/collections/records.rb', line 21

def total_records
  @total_records ||= relation.limit(nil).count
end