Module: Moysklad::Resources::LoadAll

Included in:
Assortments, Indexed
Defined in:
lib/moysklad/resources/load_all.rb

Instance Method Summary collapse

Instance Method Details

#load_all(params = {}) ⇒ Object

Raises:

  • (WrongEntriesCountError)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/moysklad/resources/load_all.rb', line 3

def load_all(params = {})
  limit = 100
  offset = 0
  rows = []
  collection = nil

  begin
    collection = list params.merge(limit: limit, offset: offset)
    rows += collection.rows
    break if collection.rows.empty?
    offset = rows.count
  end while offset<collection.meta.size

  raise WrongEntriesCountError, "При загрузке коллекции в результате колиество не совпадает с total: #{rows.count}<>#{collection.meta.size}" unless rows.count==collection.meta.size

  rows
end