Module: FlexmlsApi::PaginateHelper

Included in:
FaradayExt::FlexmlsMiddleware
Defined in:
lib/flexmls_api/paginate.rb

Overview

==Pagination Helpers Helpers to create the pagination collection

Instance Method Summary collapse

Instance Method Details

#paginate_response(results, paging_hash) ⇒ Object

==Enable pagination

  • results -- array of hashes representing api resources
  • paging_hash -- the pagination response information from the api representing paging state.

:returns:

The result set decorated as a WillPaginate::Collection


86
87
88
89
90
91
92
93
94
# File 'lib/flexmls_api/paginate.rb', line 86

def paginate_response(results, paging_hash)
  pager = Pagination.new(paging_hash)
  paged_results = WillPaginate::Collection.create(pager.current_page, pager.page_size, pager.total_rows) do |p|
    p.replace(results)
  end
  paged_results.extend PaginateResponse
  paged_results.results = results
  paged_results
end