class Vizier::CollectionPresenter
Base implementation for a Collection Presenter.
This class can be extended in your application to inherit the convenience of delegating to a collection policy's resolved scope and having a default `present` method available for wrapping other objects according to the configured factory. To specify a factory, override `presenter_factory`.
Attributes
policy[R]
presenter_factory[R]
view[R]
Public Class Methods
new(policy, view, presenter_factory: PresenterFactory.new)
click to toggle source
# File lib/vizier/collection_presenter.rb, line 13 def initialize(policy, view, presenter_factory: PresenterFactory.new) @policy = policy @view = view @presenter_factory = presenter_factory end
Public Instance Methods
each() { |resource| ... }
click to toggle source
# File lib/vizier/collection_presenter.rb, line 19 def each resources.each { |resource| yield resource } end
empty?()
click to toggle source
# File lib/vizier/collection_presenter.rb, line 23 def empty? resources.empty? end
Protected Instance Methods
present(resource)
click to toggle source
# File lib/vizier/collection_presenter.rb, line 35 def present(resource) presenter_factory[resource, policy.user, view] end
resources()
click to toggle source
# File lib/vizier/collection_presenter.rb, line 29 def resources @resources ||= policy.resolve.map do |resource| present(resource) end end