Class: Gitlab::MultiCollectionPaginator

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/multi_collection_paginator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*collections, per_page: nil) ⇒ MultiCollectionPaginator

Returns a new instance of MultiCollectionPaginator.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
# File 'lib/gitlab/multi_collection_paginator.rb', line 7

def initialize(*collections, per_page: nil)
  raise ArgumentError, 'Only 2 collections are supported' if collections.size != 2

  @per_page = (per_page || Kaminari.config.default_per_page).to_i
  @first_collection, @second_collection = collections

  raise ArgumentError, 'Page size must be at least 1' if @per_page < 1
end

Instance Attribute Details

#first_collectionObject (readonly)

Returns the value of attribute first_collection.



5
6
7
# File 'lib/gitlab/multi_collection_paginator.rb', line 5

def first_collection
  @first_collection
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



5
6
7
# File 'lib/gitlab/multi_collection_paginator.rb', line 5

def per_page
  @per_page
end

#second_collectionObject (readonly)

Returns the value of attribute second_collection.



5
6
7
# File 'lib/gitlab/multi_collection_paginator.rb', line 5

def second_collection
  @second_collection
end

Instance Method Details

#paginate(page) ⇒ Object



16
17
18
19
# File 'lib/gitlab/multi_collection_paginator.rb', line 16

def paginate(page)
  page = page.to_i
  paginated_first_collection(page) + paginated_second_collection(page)
end

#total_countObject



21
22
23
# File 'lib/gitlab/multi_collection_paginator.rb', line 21

def total_count
  @total_count ||= first_collection.size + second_collection.size
end