Sha256: 9018692c575616c459e15b096406fc966b1c9bb81ff4164affa560aa44272849

Contents?: true

Size: 657 Bytes

Versions: 35

Compression:

Stored size: 657 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

35 entries across 35 versions & 1 rubygems

Version Path
restful_resource-2.3.0 lib/restful_resource/paginated_array.rb
restful_resource-2.2.8 lib/restful_resource/paginated_array.rb
restful_resource-2.2.7 lib/restful_resource/paginated_array.rb
restful_resource-2.2.6 lib/restful_resource/paginated_array.rb
restful_resource-2.2.5 lib/restful_resource/paginated_array.rb
restful_resource-2.2.4 lib/restful_resource/paginated_array.rb
restful_resource-2.2.3 lib/restful_resource/paginated_array.rb
restful_resource-2.2.2 lib/restful_resource/paginated_array.rb
restful_resource-2.2.1 lib/restful_resource/paginated_array.rb
restful_resource-2.2.0 lib/restful_resource/paginated_array.rb
restful_resource-2.0.2 lib/restful_resource/paginated_array.rb
restful_resource-2.0.1 lib/restful_resource/paginated_array.rb
restful_resource-1.6.0 lib/restful_resource/paginated_array.rb
restful_resource-1.5.0 lib/restful_resource/paginated_array.rb
restful_resource-1.4.3 lib/restful_resource/paginated_array.rb
restful_resource-1.4.2 lib/restful_resource/paginated_array.rb
restful_resource-1.4.1 lib/restful_resource/paginated_array.rb
restful_resource-1.4.0 lib/restful_resource/paginated_array.rb
restful_resource-1.3.0 lib/restful_resource/paginated_array.rb
restful_resource-1.2.2 lib/restful_resource/paginated_array.rb