Class: ActionView::CollectionRenderer::PreloadCollectionIterator

Inherits:
SameCollectionIterator show all
Defined in:
actionview/lib/action_view/renderer/collection_renderer.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from CollectionIterator

#each, #size

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pick, #pluck, #sum, #without

Constructor Details

#initialize(collection, path, variables, relation) ⇒ PreloadCollectionIterator

Returns a new instance of PreloadCollectionIterator.


71
72
73
74
75
# File 'actionview/lib/action_view/renderer/collection_renderer.rb', line 71

def initialize(collection, path, variables, relation)
  super(collection, path, variables)
  relation.skip_preloading! unless relation.loaded?
  @relation = relation
end

Instance Method Details

#each_with_infoObject


81
82
83
84
85
# File 'actionview/lib/action_view/renderer/collection_renderer.rb', line 81

def each_with_info
  return super unless block_given?
  @relation.preload_associations(@collection)
  super
end

#from_collection(collection) ⇒ Object


77
78
79
# File 'actionview/lib/action_view/renderer/collection_renderer.rb', line 77

def from_collection(collection)
  self.class.new(collection, @path, @variables, @relation)
end