Sha256: 4e27eb1ab951318638cae11c701e70588cfb9ed8b59a7942d883c6e9e3bf9e45

Contents?: true

Size: 588 Bytes

Versions: 38

Compression:

Stored size: 588 Bytes

Contents

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

      @previous_page_url = previous_page_url
      @next_page_url = next_page_url
    end

    def previous_page
      get_page_from_url(@previous_page_url)
    end

    def next_page
      get_page_from_url(@next_page_url)
    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

38 entries across 38 versions & 1 rubygems

Version Path
restful_resource-0.8.10 lib/restful_resource/paginated_array.rb
restful_resource-0.8.9 lib/restful_resource/paginated_array.rb
restful_resource-0.8.8 lib/restful_resource/paginated_array.rb
restful_resource-0.8.7 lib/restful_resource/paginated_array.rb
restful_resource-0.8.6 lib/restful_resource/paginated_array.rb
restful_resource-0.8.5 lib/restful_resource/paginated_array.rb
restful_resource-0.8.4 lib/restful_resource/paginated_array.rb
restful_resource-0.8.3 lib/restful_resource/paginated_array.rb
restful_resource-0.8.2 lib/restful_resource/paginated_array.rb
restful_resource-0.8.1 lib/restful_resource/paginated_array.rb
restful_resource-0.8.0 lib/restful_resource/paginated_array.rb
restful_resource-0.0.11 lib/restful_resource/paginated_array.rb
restful_resource-0.0.10 lib/restful_resource/paginated_array.rb
restful_resource-0.0.9 lib/restful_resource/paginated_array.rb
restful_resource-0.0.8 lib/restful_resource/paginated_array.rb
restful_resource-0.0.7 lib/restful_resource/paginated_array.rb
restful_resource-0.0.6 lib/restful_resource/paginated_array.rb
restful_resource-0.0.5 lib/restful_resource/paginated_array.rb