Module: T::Collectable

Included in:
CLI, List, Search
Defined in:
lib/t/collectable.rb

Instance Method Summary collapse

Instance Method Details

#collect_with_cursor(collection = [], cursor = -1,, &block) ⇒ Object



4
5
6
7
8
# File 'lib/t/collectable.rb', line 4

def collect_with_cursor(collection=[], cursor=-1, &block)
  object = yield cursor
  collection += object.collection
  object.last? ? collection : collect_with_cursor(collection, object.next_cursor, &block)
end

#collect_with_max_id(collection = [], max_id = nil, &block) ⇒ Object



10
11
12
13
14
# File 'lib/t/collectable.rb', line 10

def collect_with_max_id(collection=[], max_id=nil, &block)
  array = yield max_id
  collection += array
  array.empty? ? collection : collect_with_max_id(collection, array.last.id - 1, &block)
end