class Gitlab::PaginatedResponse

Wrapper class of paginated response.

Attributes

client[RW]

Public Class Methods

new(array) click to toggle source
# File lib/gitlab/paginated_response.rb, line 6
def initialize(array)
  @array = array
end

Public Instance Methods

==(other) click to toggle source
# File lib/gitlab/paginated_response.rb, line 10
def ==(other)
  @array == other
end
auto_paginate() { |item| ... } click to toggle source
# File lib/gitlab/paginated_response.rb, line 43
def auto_paginate
  response = block_given? ? nil : []
  each_page do |page|
    if block_given?
      page.each do |item|
        yield item
      end
    else
      response += page
    end
  end
  response
end
each_page() { |current| ... } click to toggle source
# File lib/gitlab/paginated_response.rb, line 34
def each_page
  current = self
  yield current
  while current.has_next_page?
    current = current.next_page
    yield current
  end
end
first_page() click to toggle source
# File lib/gitlab/paginated_response.rb, line 71
def first_page
  return nil if @client.nil? || !has_first_page?
  path = @links.first.sub(/#{@client.endpoint}/, '')
  @client.get(path)
end
has_first_page?() click to toggle source
# File lib/gitlab/paginated_response.rb, line 67
def has_first_page?
  !(@links.nil? || @links.first.nil?)
end
has_last_page?() click to toggle source
# File lib/gitlab/paginated_response.rb, line 57
def has_last_page?
  !(@links.nil? || @links.last.nil?)
end
has_next_page?() click to toggle source
# File lib/gitlab/paginated_response.rb, line 77
def has_next_page?
  !(@links.nil? || @links.next.nil?)
end
has_prev_page?() click to toggle source
# File lib/gitlab/paginated_response.rb, line 87
def has_prev_page?
  !(@links.nil? || @links.prev.nil?)
end
inspect() click to toggle source
# File lib/gitlab/paginated_response.rb, line 14
def inspect
  @array.inspect
end
last_page() click to toggle source
# File lib/gitlab/paginated_response.rb, line 61
def last_page
  return nil if @client.nil? || !has_last_page?
  path = @links.last.sub(/#{@client.endpoint}/, '')
  @client.get(path)
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/gitlab/paginated_response.rb, line 18
def method_missing(name, *args, &block)
  if @array.respond_to?(name)
    @array.send(name, *args, &block)
  else
    super
  end
end
next_page() click to toggle source
# File lib/gitlab/paginated_response.rb, line 81
def next_page
  return nil if @client.nil? || !has_next_page?
  path = @links.next.sub(/#{@client.endpoint}/, '')
  @client.get(path)
end
parse_headers!(headers) click to toggle source
# File lib/gitlab/paginated_response.rb, line 30
def parse_headers!(headers)
  @links = PageLinks.new headers
end
prev_page() click to toggle source
# File lib/gitlab/paginated_response.rb, line 91
def prev_page
  return nil if @client.nil? || !has_prev_page?
  path = @links.prev.sub(/#{@client.endpoint}/, '')
  @client.get(path)
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/gitlab/paginated_response.rb, line 26
def respond_to_missing?(method_name, include_private = false)
  super || @array.respond_to?(method_name, include_private)
end