Class: PresenterObject::Collection
- Inherits:
-
Object
- Object
- PresenterObject::Collection
- 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
-
#collection ⇒ Object
(also: #object)
readonly
Returns the value of attribute collection.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(collection, view_context = nil) ⇒ Collection
constructor
A new instance of Collection.
Methods included from Delegation
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
#collection ⇒ Object (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_context ⇒ Object (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
#each ⇒ Object
25 26 27 |
# File 'lib/presenter_object/collection.rb', line 25 def each @collection.each { |object| yield object.presenterize view_context } end |