Class: RivetCms::EntryCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/models/rivet_cms/entry_collection.rb

Overview

Enumerable page of entries with the pagination numbers host views need.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries, page: 1, per_page: entries.size, total: entries.size, total_pages: 1) ⇒ EntryCollection

Returns a new instance of EntryCollection.



8
9
10
11
12
13
14
# File 'app/models/rivet_cms/entry_collection.rb', line 8

def initialize(entries, page: 1, per_page: entries.size, total: entries.size, total_pages: 1)
  @entries = entries
  @page = page
  @per_page = per_page
  @total = total
  @total_pages = total_pages
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



6
7
8
# File 'app/models/rivet_cms/entry_collection.rb', line 6

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



6
7
8
# File 'app/models/rivet_cms/entry_collection.rb', line 6

def per_page
  @per_page
end

#totalObject (readonly)

Returns the value of attribute total.



6
7
8
# File 'app/models/rivet_cms/entry_collection.rb', line 6

def total
  @total
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



6
7
8
# File 'app/models/rivet_cms/entry_collection.rb', line 6

def total_pages
  @total_pages
end

Instance Method Details

#[](index) ⇒ Object



29
30
31
# File 'app/models/rivet_cms/entry_collection.rb', line 29

def [](index)
  @entries[index]
end

#each(&block) ⇒ Object



16
17
18
# File 'app/models/rivet_cms/entry_collection.rb', line 16

def each(&block)
  @entries.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/rivet_cms/entry_collection.rb', line 33

def empty?
  @entries.empty?
end

#inspectObject



37
38
39
# File 'app/models/rivet_cms/entry_collection.rb', line 37

def inspect
  "#<RivetCms::EntryCollection size=#{size} page=#{page}/#{total_pages} total=#{total}>"
end

#sizeObject Also known as: length



24
25
26
# File 'app/models/rivet_cms/entry_collection.rb', line 24

def size
  @entries.size
end

#to_aObject



20
21
22
# File 'app/models/rivet_cms/entry_collection.rb', line 20

def to_a
  @entries.dup
end