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)


10
11
12
13
# File 'lib/moysklad/resources/indexed.rb', line 10

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:



18
19
20
21
22
# File 'lib/moysklad/resources/indexed.rb', line 18

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

#find(id) ⇒ Object

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

Returns:

  • Moyskald::Entities::Base



28
29
30
# File 'lib/moysklad/resources/indexed.rb', line 28

def find id
  index[id]
end

#resourceObject

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

Returns:

  • Moysklad::Resources::Base



42
43
44
# File 'lib/moysklad/resources/indexed.rb', line 42

def resource
  __getobj__
end

#uuidsArray of uuids

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

Returns:



35
36
37
# File 'lib/moysklad/resources/indexed.rb', line 35

def uuids
  index.keys
end