Class: BreweryDB::PaginatedCollection
- Inherits:
-
Collection
show all
- Includes:
- Enumerable
- Defined in:
- lib/brewery_db/paginated_collection.rb
Constant Summary
collapse
- BATCH_SIZE =
50
Instance Attribute Summary
Attributes inherited from Collection
#size
Instance Method Summary
collapse
Methods inherited from Collection
#initialize
Instance Method Details
#count(*args, &block) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/brewery_db/paginated_collection.rb', line 7
def count(*args, &block)
if args.empty? && !block_given?
size
else
super
end
end
|
#each ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/brewery_db/paginated_collection.rb', line 17
def each
return to_enum unless block_given?
while @collection.any?
@collection.each { |element| yield(element) }
break if @collection.size < BATCH_SIZE
self.response = @response.next_page
end
end
|