Module: Deli::Pagination::Collection

Defined in:
lib/deli/pagination.rb

Instance Method Summary collapse

Instance Method Details

#countObject

:nodoc:



99
100
101
# File 'lib/deli/pagination.rb', line 99

def count #:nodoc:
  limit_value ? length : super
end

#current_pageObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/deli/pagination.rb', line 52

def current_page
  unless @current_page
    if offset_value.blank? || offset_value.zero?
      @current_page = 1
    else
      @current_page = (offset_value.to_f / limit_value).to_i + 1
    end
  end
  
  @current_page
end

#end_countObject



48
49
50
# File 'lib/deli/pagination.rb', line 48

def end_count
  @end_count ||= start_count + size
end

#first_pageObject



80
81
82
# File 'lib/deli/pagination.rb', line 80

def first_page
  1
end

#has_next?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/deli/pagination.rb', line 36

def has_next?
  last_page > current_page
end

#has_prev?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/deli/pagination.rb', line 40

def has_prev?
  current_page > first_page
end

#last_pageObject



84
85
86
# File 'lib/deli/pagination.rb', line 84

def last_page
  page_count
end

#next_pageObject



64
65
66
67
68
69
70
# File 'lib/deli/pagination.rb', line 64

def next_page
  unless @next_page
    @next_page = current_page + 1 > last_page ? last_page : current_page + 1
  end

  @next_page
end

#page_countObject



92
93
94
# File 'lib/deli/pagination.rb', line 92

def page_count
  @page_count ||= (total_count.to_f / page_size).ceil
end

#page_sizeObject



88
89
90
# File 'lib/deli/pagination.rb', line 88

def page_size
  @page_size ||= limit_value
end

#prev_pageObject



72
73
74
75
76
77
78
# File 'lib/deli/pagination.rb', line 72

def prev_page
  unless @prev_page
    @prev_page = current_page - 1 < first_page ? first_page : current_page - 1
  end

  @prev_page
end

#start_countObject



44
45
46
# File 'lib/deli/pagination.rb', line 44

def start_count
  @start_count ||= (((current_page || 1) - 1) * page_size)
end

#total_countObject

:nodoc:



104
105
106
# File 'lib/deli/pagination.rb', line 104

def total_count
  @total_count ||= proxy_scope.count(proxy_options.except(:limit, :offset, :order))
end