Class: PaginatedCollection::Base

Inherits:
Array
  • Object
show all
Defined in:
lib/paginated_collection/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*members, pagination: {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
# File 'lib/paginated_collection/base.rb', line 6

def initialize *members, pagination: {}
  p = pagination.symbolize_keys
  @pagination = Pagination.new(p[:current_page],
                               p[:total_pages],
                               p[:per_page],
                               p[:total])

  super members
end

Instance Attribute Details

#paginationObject

Returns the value of attribute pagination.



4
5
6
# File 'lib/paginated_collection/base.rb', line 4

def pagination
  @pagination
end

Class Method Details

.build_with(elems, pagination: {}, &block) ⇒ Object



16
17
18
19
# File 'lib/paginated_collection/base.rb', line 16

def self.build_with(elems, pagination: {}, &block)
  members = elems.map { |e| block.call(e) }
  new(*members, pagination: pagination)
end