Class: Gitlab::PaginatedResponse
- Inherits:
-
Object
- Object
- Gitlab::PaginatedResponse
show all
- Defined in:
- lib/gitlab/paginated_response.rb
Overview
Wrapper class of paginated response.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PaginatedResponse.
8
9
10
|
# File 'lib/gitlab/paginated_response.rb', line 8
def initialize(array)
@array = array
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/gitlab/paginated_response.rb', line 20
def method_missing(name, *args, &block)
if @array.respond_to?(name)
@array.send(name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6
7
8
|
# File 'lib/gitlab/paginated_response.rb', line 6
def client
@client
end
|
Instance Method Details
#==(other) ⇒ Object
12
13
14
|
# File 'lib/gitlab/paginated_response.rb', line 12
def ==(other)
@array == other
end
|
#auto_paginate ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/gitlab/paginated_response.rb', line 45
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| ... } ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/gitlab/paginated_response.rb', line 36
def each_page
current = self
yield current
while current.has_next_page?
current = current.next_page
yield current
end
end
|
#first_page ⇒ Object
76
77
78
79
80
81
|
# File 'lib/gitlab/paginated_response.rb', line 76
def first_page
return nil if @client.nil? || !has_first_page?
path = @links.first.sub(/#{@client.endpoint}/, '')
@client.get(path)
end
|
#first_page? ⇒ Boolean
Also known as:
has_first_page?
71
72
73
|
# File 'lib/gitlab/paginated_response.rb', line 71
def first_page?
!(@links.nil? || @links.first.nil?)
end
|
#inspect ⇒ Object
16
17
18
|
# File 'lib/gitlab/paginated_response.rb', line 16
def inspect
@array.inspect
end
|
#last_page ⇒ Object
64
65
66
67
68
69
|
# File 'lib/gitlab/paginated_response.rb', line 64
def last_page
return nil if @client.nil? || !has_last_page?
path = @links.last.sub(/#{@client.endpoint}/, '')
@client.get(path)
end
|
#last_page? ⇒ Boolean
Also known as:
has_last_page?
59
60
61
|
# File 'lib/gitlab/paginated_response.rb', line 59
def last_page?
!(@links.nil? || @links.last.nil?)
end
|
#next_page ⇒ Object
88
89
90
91
92
93
|
# File 'lib/gitlab/paginated_response.rb', line 88
def next_page
return nil if @client.nil? || !has_next_page?
path = @links.next.sub(/#{@client.endpoint}/, '')
@client.get(path)
end
|
#next_page? ⇒ Boolean
Also known as:
has_next_page?
83
84
85
|
# File 'lib/gitlab/paginated_response.rb', line 83
def next_page?
!(@links.nil? || @links.next.nil?)
end
|
32
33
34
|
# File 'lib/gitlab/paginated_response.rb', line 32
def ()
@links = PageLinks.new
end
|
#prev_page ⇒ Object
100
101
102
103
104
105
|
# File 'lib/gitlab/paginated_response.rb', line 100
def prev_page
return nil if @client.nil? || !has_prev_page?
path = @links.prev.sub(/#{@client.endpoint}/, '')
@client.get(path)
end
|
#prev_page? ⇒ Boolean
Also known as:
has_prev_page?
95
96
97
|
# File 'lib/gitlab/paginated_response.rb', line 95
def prev_page?
!(@links.nil? || @links.prev.nil?)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
28
29
30
|
# File 'lib/gitlab/paginated_response.rb', line 28
def respond_to_missing?(method_name, include_private = false)
super || @array.respond_to?(method_name, include_private)
end
|