Class: Gitlab::MultiCollectionPaginator
- Inherits:
-
Object
- Object
- Gitlab::MultiCollectionPaginator
- Defined in:
- lib/gitlab/multi_collection_paginator.rb
Instance Attribute Summary collapse
-
#first_collection ⇒ Object
readonly
Returns the value of attribute first_collection.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#second_collection ⇒ Object
readonly
Returns the value of attribute second_collection.
Instance Method Summary collapse
-
#initialize(*collections, per_page: nil) ⇒ MultiCollectionPaginator
constructor
A new instance of MultiCollectionPaginator.
- #paginate(page) ⇒ Object
- #total_count ⇒ Object
Constructor Details
#initialize(*collections, per_page: nil) ⇒ MultiCollectionPaginator
Returns a new instance of MultiCollectionPaginator.
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_collection ⇒ Object (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_page ⇒ Object (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_collection ⇒ Object (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_count ⇒ Object
21 22 23 |
# File 'lib/gitlab/multi_collection_paginator.rb', line 21 def total_count @total_count ||= first_collection.size + second_collection.size end |