Class: PresenterObject::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Delegation
Defined in:
lib/presenter_object/collection.rb

Overview

Presenter superclass for collections. Create your own collection presenter by sub-classing ‘PresenterObject::Collection`.

e.g:

class DocumentCollectionPresenter << PresenterObject::Collection
 .. add methods here ..
end

Create a presenter instance by giving it a model instance e.g:

documents = DocumentCollectionPresenter.new Document.where(publish: true) 
documents.method_that_presents_collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Delegation

#method_missing, #respond_to?

Constructor Details

#initialize(collection, view_context = nil) ⇒ Collection

Returns a new instance of Collection.



20
21
22
23
# File 'lib/presenter_object/collection.rb', line 20

def initialize(collection, view_context = nil)
  @collection = collection
  @view_context = view_context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PresenterObject::Delegation

Instance Attribute Details

#collectionObject (readonly) Also known as: object

Returns the value of attribute collection.



17
18
19
# File 'lib/presenter_object/collection.rb', line 17

def collection
  @collection
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



17
18
19
# File 'lib/presenter_object/collection.rb', line 17

def view_context
  @view_context
end

Instance Method Details

#eachObject



25
26
27
# File 'lib/presenter_object/collection.rb', line 25

def each
  @collection.each { |object| yield object.presenterize view_context }
end