Module: Workarea::Search::Pagination

Instance Method Summary collapse

Instance Method Details

#each_by(by, &block) ⇒ Object



30
31
32
33
34
35
36
37
# File 'app/queries/workarea/search/pagination.rb', line 30

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



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

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
# File 'app/queries/workarea/search/pagination.rb', line 9

def per_page
  params[:per_page].presence || Workarea.config.per_page
end

#resultsObject



21
22
23
24
25
26
27
28
# File 'app/queries/workarea/search/pagination.rb', line 21

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

#sizeObject



13
14
15
# File 'app/queries/workarea/search/pagination.rb', line 13

def size
  super || per_page
end