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 22 23 24 25 |
# File 'lib/tacokit/collection.rb', line 12 def initialize(client, method, path, ) @client = client @method = method @path = path @options = @before = .fetch(:before, nil) @limit = .fetch(:limit, 50) @max = .fetch(:max, MAX) @collection = [] fetch_next_page end |
Instance Method Details
#each(start = 0) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tacokit/collection.rb', line 27 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 |