Class: HasHelpers::Resource::InfoCollectionPresenter

Inherits:
BasePresenter
  • Object
show all
Defined in:
app/presenters/has_helpers/resource/info_collection_presenter.rb

Overview

This class is used to present a collection of related entities. Be careful to use ::new instead of ::wrap to instantiate.

Instance Attribute Summary collapse

Attributes inherited from BasePresenter

#errors, #wrapped_object

Instance Method Summary collapse

Methods inherited from BasePresenter

#==, #error_on, #initialize, wrap, wrap_with_options

Methods included from Attributes

included

Constructor Details

This class inherits a constructor from HasHelpers::BasePresenter

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HasHelpers::BasePresenter

Instance Attribute Details

#entitiesObject

FIXME: It seems like there should be a better way to accomplish is_first, is_last without putting logic into the template (see _collection.html.erb)



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/presenters/has_helpers/resource/info_collection_presenter.rb', line 8

def entities
  entities = @entities

  if entities.length == 1
    entities.first.is_first = true
    entities.first.is_last = true
  elsif entities.length > 1
    entities.first.is_first = true
    entities.first.is_last = false

    entities[1..-2] && entities[1..-2].each do |related_entity|
      related_entity.is_first = false
      related_entity.is_last = false
    end

    entities.last.is_first = false
    entities.last.is_last = true
  end

  entities
end

Instance Method Details

#has_multiple?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/presenters/has_helpers/resource/info_collection_presenter.rb', line 30

def has_multiple?
  @entities && @entities.length > 1
end