Class: SentryApi::PaginatedResponse
- Inherits:
-
Object
- Object
- SentryApi::PaginatedResponse
show all
- Defined in:
- lib/sentry-api/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/sentry-api/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/sentry-api/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/sentry-api/paginated_response.rb', line 4
def client
@client
end
|
Instance Method Details
#==(other) ⇒ Object
10
11
12
|
# File 'lib/sentry-api/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/sentry-api/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/sentry-api/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
|
#has_next_page? ⇒ Boolean
57
58
59
|
# File 'lib/sentry-api/paginated_response.rb', line 57
def has_next_page?
!(@links.nil? || @links.next.nil?)
end
|
#has_prev_page? ⇒ Boolean
66
67
68
|
# File 'lib/sentry-api/paginated_response.rb', line 66
def has_prev_page?
!(@links.nil? || @links.previous.nil?)
end
|
#inspect ⇒ Object
14
15
16
|
# File 'lib/sentry-api/paginated_response.rb', line 14
def inspect
@array.inspect
end
|
#next_page ⇒ Object
61
62
63
64
|
# File 'lib/sentry-api/paginated_response.rb', line 61
def next_page
return nil if @client.nil? || !has_next_page?
@links.next
end
|
30
31
32
|
# File 'lib/sentry-api/paginated_response.rb', line 30
def ()
@links = PageLinks.new
end
|
#prev_page ⇒ Object
70
71
72
73
|
# File 'lib/sentry-api/paginated_response.rb', line 70
def prev_page
return nil if @client.nil? || !has_prev_page?
@links.previous
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
26
27
28
|
# File 'lib/sentry-api/paginated_response.rb', line 26
def respond_to_missing?(method_name, include_private = false)
super || @array.respond_to?(method_name, include_private)
end
|