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(&block) ⇒ Object
50 51 52 53 54 | # File 'lib/gitlab/paginated_response.rb', line 50 def auto_paginate(&block) return lazy_paginate.to_a unless block lazy_paginate.each(&block) end |
#client_relative_path(link) ⇒ Object
110 111 112 113 | # File 'lib/gitlab/paginated_response.rb', line 110 def client_relative_path(link) client_endpoint_path = URI.parse(@client.endpoint).request_uri URI.parse(link).request_uri.sub(client_endpoint_path, '') end |
#each_page {|current| ... } ⇒ Object
37 38 39 40 41 42 43 44 | # File 'lib/gitlab/paginated_response.rb', line 37 def each_page current = self yield current while current.has_next_page? current = current.next_page yield current end end |
#first_page ⇒ Object
82 83 84 85 86 | # File 'lib/gitlab/paginated_response.rb', line 82 def first_page return nil if @client.nil? || !has_first_page? @client.get(client_relative_path(@links.first)) end |
#first_page? ⇒ Boolean Also known as: has_first_page?
77 78 79 | # File 'lib/gitlab/paginated_response.rb', line 77 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
71 72 73 74 75 | # File 'lib/gitlab/paginated_response.rb', line 71 def last_page return nil if @client.nil? || !has_last_page? @client.get(client_relative_path(@links.last)) end |
#last_page? ⇒ Boolean Also known as: has_last_page?
66 67 68 | # File 'lib/gitlab/paginated_response.rb', line 66 def last_page? !(@links.nil? || @links.last.nil?) end |
#lazy_paginate ⇒ Object
46 47 48 | # File 'lib/gitlab/paginated_response.rb', line 46 def lazy_paginate to_enum(:each_page).lazy.flat_map(&:to_ary) end |
#next_page ⇒ Object
93 94 95 96 97 | # File 'lib/gitlab/paginated_response.rb', line 93 def next_page return nil if @client.nil? || !has_next_page? @client.get(client_relative_path(@links.next)) end |
#next_page? ⇒ Boolean Also known as: has_next_page?
88 89 90 | # File 'lib/gitlab/paginated_response.rb', line 88 def next_page? !(@links.nil? || @links.next.nil?) end |
#paginate_with_limit(limit, &block) ⇒ Object
56 57 58 59 60 | # File 'lib/gitlab/paginated_response.rb', line 56 def paginate_with_limit(limit, &block) return lazy_paginate.take(limit).to_a unless block lazy_paginate.take(limit).each(&block) end |
#prev_page ⇒ Object
104 105 106 107 108 | # File 'lib/gitlab/paginated_response.rb', line 104 def prev_page return nil if @client.nil? || !has_prev_page? @client.get(client_relative_path(@links.prev)) end |
#prev_page? ⇒ Boolean Also known as: has_prev_page?
99 100 101 | # File 'lib/gitlab/paginated_response.rb', line 99 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 |
#total ⇒ Object
62 63 64 | # File 'lib/gitlab/paginated_response.rb', line 62 def total @total.total end |