Class: StrongPresenter::CollectionPresenter
- Inherits:
-
Object
- Object
- StrongPresenter::CollectionPresenter
- Includes:
- Enumerable, Delegation, Permissible, ViewHelpers
- Defined in:
- lib/strong_presenter/collection_presenter.rb
Class Method Summary collapse
-
.presents_with(presenter) ⇒ Object
Sets the presenter used to wrap models in the collection.
Instance Method Summary collapse
-
#initialize(object, options = {}) {|_self| ... } ⇒ CollectionPresenter
constructor
A new instance of CollectionPresenter.
-
#permit!(*attribute_paths) ⇒ Object
Permits given attributes, with propagation to collection items.
-
#reload! ⇒ Object
Resets item presenters - clears the cache.
- #to_s ⇒ Object
Methods included from Permissible
#permit_all!, #select_permitted
Methods included from ViewHelpers
Constructor Details
#initialize(object, options = {}) {|_self| ... } ⇒ CollectionPresenter
Returns a new instance of CollectionPresenter.
13 14 15 16 17 18 19 |
# File 'lib/strong_presenter/collection_presenter.rb', line 13 def initialize(object, = {}) .assert_valid_keys(:with) @object = object @presenter_class = [:with] yield self if block_given? end |
Class Method Details
.presents_with(presenter) ⇒ Object
Sets the presenter used to wrap models in the collection
68 69 70 71 |
# File 'lib/strong_presenter/collection_presenter.rb', line 68 def presents_with presenter @presenter_class = presenter self end |
Instance Method Details
#permit!(*attribute_paths) ⇒ Object
Permits given attributes, with propagation to collection items.
27 28 29 30 31 |
# File 'lib/strong_presenter/collection_presenter.rb', line 27 def permit! *attribute_paths super @collection.each { |presenter| presenter.permit! *attribute_paths } unless @collection.nil? self end |
#reload! ⇒ Object
Resets item presenters - clears the cache
34 35 36 37 |
# File 'lib/strong_presenter/collection_presenter.rb', line 34 def reload! @collection = nil self end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/strong_presenter/collection_presenter.rb', line 21 def to_s "#<#{self.class.name} of #{presenter_class || "inferred presenters"} for #{object.inspect}>" end |