Class: Paginator::Page

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/active_scaffold/paginator.rb,
lib/active_scaffold/extensions/paginator_extensions.rb

Overview

Page object

Retrieves items for a page and provides metadata about the position of the page in the paginator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pager, number, &select) ⇒ Page

:nodoc:



82
83
84
85
86
# File 'lib/active_scaffold/paginator.rb', line 82

def initialize(pager, number, &select) #:nodoc:
  @pager, @number = pager, number
  @offset = (number - 1) * pager.per_page
  @select = select
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number



80
81
82
# File 'lib/active_scaffold/paginator.rb', line 80

def number
  @number
end

#pagerObject (readonly)

Returns the value of attribute pager



80
81
82
# File 'lib/active_scaffold/paginator.rb', line 80

def pager
  @pager
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



128
129
130
# File 'lib/active_scaffold/paginator.rb', line 128

def ==(other) #:nodoc:
  @pager == other.pager && number == other.number
end

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'lib/active_scaffold/extensions/paginator_extensions.rb', line 27

def empty?
  if @pager.infinite?
    items.to_a.empty?
  else
    @pager.count == 0
  end
end

#first_item_numberObject

The “item number” of the first item on this page



115
116
117
# File 'lib/active_scaffold/paginator.rb', line 115

def first_item_number
  1 + @offset
end

#itemsObject

Retrieve the items for this page

  • Caches



90
91
92
# File 'lib/active_scaffold/paginator.rb', line 90

def items
  @items ||= @select.call
end

#last_item_numberObject

The “item number” of the last item on this page



120
121
122
123
124
125
126
# File 'lib/active_scaffold/paginator.rb', line 120

def last_item_number
  if next?
    @offset + @pager.per_page
  else
    @pager.count
  end
end

#nextObject

Get next page (if possible)



110
111
112
# File 'lib/active_scaffold/paginator.rb', line 110

def next
  @pager.page(@number + 1) if next?
end

#next?Boolean

Checks to see if there's a page after this one

Returns:

  • (Boolean)


105
106
107
# File 'lib/active_scaffold/paginator.rb', line 105

def next?
  @number < @pager.number_of_pages
end

#next_with_infinite?Boolean

Checks to see if there's a page after this one

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/active_scaffold/extensions/paginator_extensions.rb', line 21

def next_with_infinite?
  return true if @pager.infinite?
  next_without_infinite?
end

#prevObject

Get previous page (if possible)



100
101
102
# File 'lib/active_scaffold/paginator.rb', line 100

def prev
  @pager.page(@number - 1) if prev?
end

#prev?Boolean

Checks to see if there's a page before this one

Returns:

  • (Boolean)


95
96
97
# File 'lib/active_scaffold/paginator.rb', line 95

def prev?
  @number > 1
end