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.
6
7
8
|
# File 'lib/gitlab/paginated_response.rb', line 6
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
18
19
20
21
22
23
24
|
# 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
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
4
5
6
|
# File 'lib/gitlab/paginated_response.rb', line 4
def client
@client
end
|
Instance Method Details
#==(other) ⇒ Object
10
11
12
|
# File 'lib/gitlab/paginated_response.rb', line 10
def ==(other)
@array == other
end
|
#auto_paginate ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# 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| ... } ⇒ Object
34
35
36
37
38
39
40
41
|
# 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 ⇒ Object
71
72
73
74
75
|
# 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? ⇒ Boolean
67
68
69
|
# File 'lib/gitlab/paginated_response.rb', line 67
def has_first_page?
!(@links.nil? || @links.first.nil?)
end
|
#has_last_page? ⇒ Boolean
57
58
59
|
# File 'lib/gitlab/paginated_response.rb', line 57
def has_last_page?
!(@links.nil? || @links.last.nil?)
end
|
#has_next_page? ⇒ Boolean
77
78
79
|
# File 'lib/gitlab/paginated_response.rb', line 77
def has_next_page?
!(@links.nil? || @links.next.nil?)
end
|
#has_prev_page? ⇒ Boolean
87
88
89
|
# File 'lib/gitlab/paginated_response.rb', line 87
def has_prev_page?
!(@links.nil? || @links.prev.nil?)
end
|
#inspect ⇒ Object
14
15
16
|
# File 'lib/gitlab/paginated_response.rb', line 14
def inspect
@array.inspect
end
|
#last_page ⇒ Object
61
62
63
64
65
|
# 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
|
#next_page ⇒ Object
81
82
83
84
85
|
# 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
|
30
31
32
|
# File 'lib/gitlab/paginated_response.rb', line 30
def ()
@links = PageLinks.new
end
|
#prev_page ⇒ Object
91
92
93
94
95
|
# 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) ⇒ Boolean
26
27
28
|
# 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
|