Sha256: 5cd9f3fe82cf5dea69343a7b25d0677ce792935c2143df4ebbd362be5556fd34

Contents?: true

Size: 749 Bytes

Versions: 16

Compression:

Stored size: 749 Bytes

Contents

module Restly::Collection::Pagination

  def page(num)
    with_params(page: num, per_page: per_page).all.paginate(page: num, per_page: per_page)
  end

  def current_page
    pagination[:current_page] || pagination[:page]
  end

  def per_page
    @pagination_opts[:per_page] || pagination[:per_page]
  end

  def response_per_page
    pagination[:per_page]
  end

  def total_pages
    pagination[:total_pages]
  end

  def total_entries
    pagination[:total_entries]
  end

  private

  def pagination
    parsed = @response.parsed || {}
    pagination = parsed[:pagination] || parsed
    pagination.select!{ |k,v| /page|current_page|entries|total_entries|per_page|total_pages|total/ =~ k.to_s }
    pagination.with_indifferent_access
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
restly-0.0.1.beta.2 lib/restly/collection/pagination.rb
restly-0.0.1.beta.1 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.22 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.19 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.18 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.16 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.12 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.11 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.10 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.9 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.8 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.7 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.6 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.4 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.3 lib/restly/collection/pagination.rb
restly-0.0.1.alpha.2 lib/restly/collection/pagination.rb