Class: Folio::Enumerable::Decorator

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Ordinal
Defined in:
lib/folio/core_ext/enumerable.rb

Constant Summary collapse

METHODS =
self.instance_methods - SimpleDelegator.instance_methods

Constants included from Folio

VERSION

Instance Method Summary collapse

Methods included from Ordinal

#configure_pagination

Methods included from Folio

#configure_pagination, #paginate

Methods included from PerPageIncluder

#included

Methods included from PerPage

#per_page

Instance Method Details

#build_pageObject

just fill a typical ordinal page



8
9
10
# File 'lib/folio/core_ext/enumerable.rb', line 8

def build_page
  ::Folio::Ordinal::Page.create
end

#default_per_pageObject

things that already included Enumerable won’t have extended the PerPage, so the instance’s default default_per_page method looking at self.class.per_page won’t work. point it back at Folio.per_page



25
26
27
# File 'lib/folio/core_ext/enumerable.rb', line 25

def default_per_page
  Folio.per_page
end

#fill_page(page) ⇒ Object

fill by taking the appropriate slice out of the enumerable. if the slice is empty and it’s not the first page, it’s invalid



14
15
16
17
18
19
# File 'lib/folio/core_ext/enumerable.rb', line 14

def fill_page(page)
  slice = self.each_slice(page.per_page).first(page.current_page)[page.current_page-1] || []
  raise ::Folio::InvalidPage if slice.empty? && page.current_page != page.first_page
  page.replace slice
  page
end