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.30 lib/restful_resource/paginated_array.rb
restful_resource-0.8.29 lib/restful_resource/paginated_array.rb
restful_resource-0.8.28 lib/restful_resource/paginated_array.rb
restful_resource-0.8.27 lib/restful_resource/paginated_array.rb
restful_resource-0.8.26 lib/restful_resource/paginated_array.rb
restful_resource-0.8.25 lib/restful_resource/paginated_array.rb
restful_resource-0.8.24 lib/restful_resource/paginated_array.rb
restful_resource-0.8.23 lib/restful_resource/paginated_array.rb
restful_resource-0.8.22 lib/restful_resource/paginated_array.rb
restful_resource-0.8.21 lib/restful_resource/paginated_array.rb
restful_resource-0.8.20 lib/restful_resource/paginated_array.rb
restful_resource-0.8.19 lib/restful_resource/paginated_array.rb
restful_resource-0.8.18 lib/restful_resource/paginated_array.rb
restful_resource-0.8.17 lib/restful_resource/paginated_array.rb
restful_resource-0.8.16 lib/restful_resource/paginated_array.rb
restful_resource-0.8.15 lib/restful_resource/paginated_array.rb
restful_resource-0.8.14 lib/restful_resource/paginated_array.rb
restful_resource-0.8.13 lib/restful_resource/paginated_array.rb
restful_resource-0.8.12 lib/restful_resource/paginated_array.rb
restful_resource-0.8.11 lib/restful_resource/paginated_array.rb