Method: ApiResource::Resource.all_pages

Defined in:
lib/api-resource/resource.rb

.all_pages(params = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/api-resource/resource.rb', line 81

def self.all_pages(params={})
  params  = { page: 1, per_page: default_per_page }.merge(params)
  per_page = params[:per_page].to_i
  page     = params[:page].to_i
  begin
    params[:page] = page
    result         = self.where(params)
    total_count    = result.try :total_count
    arr            = result.to_a
    count          = arr.length
    break if yield(arr, page, per_page, total_count) || (page - 1) * per_page + count >= total_count
    page += 1
  end while true
end