Module: Workarea::Search::Pagination

Instance Method Summary collapse

Instance Method Details

#each_by(by, &block) ⇒ Object



33
34
35
36
37
38
39
40
# File 'app/queries/workarea/search/pagination.rb', line 33

def each_by(by, &block)
  i = 0

  while (results = get_each_by_results(by, i)) && results.present?
    results.each { |result| yield(result) }
    i += 1
  end
end

#fromObject



20
21
22
# File 'app/queries/workarea/search/pagination.rb', line 20

def from
  size * (page - 1)
end

#pageObject



4
5
6
7
# File 'app/queries/workarea/search/pagination.rb', line 4

def page
  tmp = params[:page].present? ? params[:page].to_i : 1
  tmp > 0 ? tmp : 1
end

#per_pageObject



9
10
11
12
13
14
# File 'app/queries/workarea/search/pagination.rb', line 9

def per_page
  return Workarea.config.per_page if params[:per_page].blank?

  tmp = params[:per_page].to_i
  tmp > 0 ? tmp : Workarea.config.per_page
end

#resultsObject



24
25
26
27
28
29
30
31
# File 'app/queries/workarea/search/pagination.rb', line 24

def results
  @paged_results ||= PagedArray.from(
    super,
    page,
    per_page,
    total
  )
end

#sizeObject



16
17
18
# File 'app/queries/workarea/search/pagination.rb', line 16

def size
  super || per_page
end