Class: Moysklad::Resources::Indexed

Inherits:
SimpleDelegator
  • Object
show all
Includes:
IndexedCache, LoadAll, WhereFilter
Defined in:
lib/moysklad/resources/indexed.rb

Direct Known Subclasses

EmbeddedEntityMetadataIndexed

Constant Summary collapse

WrongEntriesCountError =
Class.new StandardError
NoIdInEntity =
Class.new StandardError

Instance Method Summary collapse

Methods included from IndexedCache

#cache!

Methods included from LoadAll

#load_all

Methods included from WhereFilter

#findWhere, #where

Constructor Details

#initialize(resource) ⇒ Indexed

Returns a new instance of Indexed.

Raises:

  • (TypeError)


14
15
16
17
# File 'lib/moysklad/resources/indexed.rb', line 14

def initialize resource
  raise TypeError, 'resource должен быть Moysklad::Resources::Base' unless resource.is_a? Moysklad::Resources::Base
  super resource
end

Instance Method Details

#all(params = {}) ⇒ Array of Moysklad::Entities::Base

Автоматически подгружает постранично данныез из API и возвращает их все сразу.

Returns:



22
23
24
25
26
# File 'lib/moysklad/resources/indexed.rb', line 22

def all(params = {})
  cache_fetch do
    pull_list(params)
  end
end

#find(id) ⇒ Object

Возвращает запрашивемую запись из кеша. Предварительно подгружает все записи через метод ‘all`

Returns:

  • Moyskald::Entities::Base



32
33
34
# File 'lib/moysklad/resources/indexed.rb', line 32

def find id
  index[id]
end

#resourceObject

Неиндексированный ресурс

Returns:

  • Moysklad::Resources::Base



46
47
48
# File 'lib/moysklad/resources/indexed.rb', line 46

def resource
  __getobj__
end

#uuidsArray of uuids

Перечень id-ов всех элементов в ресуресе

Returns:



39
40
41
# File 'lib/moysklad/resources/indexed.rb', line 39

def uuids
  index.keys
end