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
# File 'lib/gitlab/multi_collection_paginator.rb', line 7

def initialize(*collections, per_page: nil)
  raise ArgumentError.new('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
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


14
15
16
17
# File 'lib/gitlab/multi_collection_paginator.rb', line 14

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

#total_countObject


19
20
21
# File 'lib/gitlab/multi_collection_paginator.rb', line 19

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