Sha256: b3d3e0856f466c4ab0297a5d1c8bba36223d4b8c29a0b2c167e0d1e29e6efff5

Contents?: true

Size: 658 Bytes

Versions: 26

Compression:

Stored size: 658 Bytes

Contents

module RestfulResource
  class PaginatedArray < Array
    def initialize(original_array, previous_page_url:, next_page_url:, total_count:)
      super(original_array)

      @previous_page_url = previous_page_url
      @next_page_url = next_page_url
      @total_count = total_count
    end

    def previous_page
      get_page_from_url(@previous_page_url)
    end

    def next_page
      get_page_from_url(@next_page_url)
    end

    def total_count
      @total_count.to_i
    end

    private

    def get_page_from_url(url)
      return nil unless url

      params = Rack::Utils.parse_query URI(url).query
      params['page'].to_i
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
restful_resource-2.18.1 lib/restful_resource/paginated_array.rb
restful_resource-2.18.0 lib/restful_resource/paginated_array.rb
restful_resource-2.17.0 lib/restful_resource/paginated_array.rb
restful_resource-2.16.0 lib/restful_resource/paginated_array.rb
restful_resource-2.15.0 lib/restful_resource/paginated_array.rb
restful_resource-2.14.0 lib/restful_resource/paginated_array.rb
restful_resource-2.13.4 lib/restful_resource/paginated_array.rb
restful_resource-2.13.3 lib/restful_resource/paginated_array.rb
restful_resource-2.13.2 lib/restful_resource/paginated_array.rb
restful_resource-2.13.1 lib/restful_resource/paginated_array.rb
restful_resource-2.13.0 lib/restful_resource/paginated_array.rb
restful_resource-2.12.1 lib/restful_resource/paginated_array.rb
restful_resource-2.12.0 lib/restful_resource/paginated_array.rb
restful_resource-2.11.0 lib/restful_resource/paginated_array.rb
restful_resource-2.10.3 lib/restful_resource/paginated_array.rb
restful_resource-2.10.1 lib/restful_resource/paginated_array.rb
restful_resource-2.10.0 lib/restful_resource/paginated_array.rb
restful_resource-2.9.1 lib/restful_resource/paginated_array.rb
restful_resource-2.8.0 lib/restful_resource/paginated_array.rb
restful_resource-2.7.0 lib/restful_resource/paginated_array.rb