Class: Tacokit::Collection
- Inherits:
-
Object
- Object
- Tacokit::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/tacokit/collection.rb
Constant Summary collapse
- MAX =
1000
Instance Method Summary collapse
- #each(start = 0) ⇒ Object
-
#initialize(client, method, path, options) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(client, method, path, options) ⇒ Collection
Returns a new instance of Collection.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tacokit/collection.rb', line 12 def initialize(client, method, path, ) @client, @method, @path, @options = client, method, path, @page = .fetch(:page, 0) @limit = .fetch(:limit, 50) @collection = [] fetch_next_page end |
Instance Method Details
#each(start = 0) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tacokit/collection.rb', line 23 def each(start = 0) return to_enum(:each, start) unless block_given? Array(@collection[start..-1]).each do |element| yield(element) end unless last? start = [@collection.size, start].max fetch_next_page each(start, &Proc.new) end self end |