Class: Tacokit::Collection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/tacokit/collection.rb

Constant Summary collapse

MAX =
1000

Instance Method Summary collapse

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, options)
  @client, @method, @path, @options = client, method, path, options

  @page  = options.fetch(:page, 0)
  @limit = options.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