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



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

def each(&block)
  records.each { |record| block_given? ? yield(record) : record }
end

#each_in_batches(batch_size = nil, &block) ⇒ Object



39
40
41
42
# File 'lib/active_record/collections/records.rb', line 39

def each_in_batches(batch_size=nil, &block)
  per_batch!(batch_size)
  flat_batch_map.each { |record| block_given? ? yield(record) : record }
end

#flat_map(&block) ⇒ Object



53
54
55
# File 'lib/active_record/collections/records.rb', line 53

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

#flat_map_in_batches(batch_size = nil, &block) ⇒ Object



57
58
59
60
# File 'lib/active_record/collections/records.rb', line 57

def flat_map_in_batches(batch_size=nil, &block)
  per_batch!(batch_size)
  flat_batch_map.map { |record| block_given? ? yield(record) : record }
end

#lengthObject



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

def length
  to_a.length
end

#map(&block) ⇒ Object



44
45
46
# File 'lib/active_record/collections/records.rb', line 44

def map(&block)
  each.map { |record| block_given? ? yield(record) : record }
end

#map_in_batches(batch_size = nil, &block) ⇒ Object



48
49
50
51
# File 'lib/active_record/collections/records.rb', line 48

def map_in_batches(batch_size=nil, &block)
  per_batch!(batch_size)
  flat_batch_map.map { |record| block_given? ? yield(record) : record }
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



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

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



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

def total_count
  @total_count ||= relation.dup.limit(nil).offset(nil).count
end