class Moysklad::Resources::Indexed
Constants
- NoIdInEntity
- WrongEntriesCountError
Public Class Methods
new(resource)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
all(params = {})
click to toggle source
Автоматически подгружает постранично данныез из API и возвращает их все сразу.
@return [Array of Moysklad::Entities::Base
]
# File lib/moysklad/resources/indexed.rb, line 18 def all(params = {}) cache_fetch do pull_list(params) end end
find(id)
click to toggle source
Возвращает запрашивемую запись из кеша. Предварительно подгружает все записи через метод ‘all`
@return Moyskald::Entities::Base
# File lib/moysklad/resources/indexed.rb, line 28 def find id index[id] end
resource()
click to toggle source
Неиндексированный ресурс
@return Moysklad::Resources::Base
# File lib/moysklad/resources/indexed.rb, line 42 def resource __getobj__ end
uuids()
click to toggle source
Перечень id-ов всех элементов в ресуресе
@return [Array of uuids]
# File lib/moysklad/resources/indexed.rb, line 35 def uuids index.keys end
Private Instance Methods
index()
click to toggle source
# File lib/moysklad/resources/indexed.rb, line 52 def index all unless cached_index cached_index end
prepare_index(list)
click to toggle source
# File lib/moysklad/resources/indexed.rb, line 61 def prepare_index list i={} list.each do |r| raise NoIdInEntity, "У объекта нет id: #{r}" unless r.respond_to?(:id) && r.id i[r.id]=r end return i end
pull_list(params={})
click to toggle source
# File lib/moysklad/resources/indexed.rb, line 57 def pull_list(params={}) load_all(params) end
values()
click to toggle source
# File lib/moysklad/resources/indexed.rb, line 48 def values index.values end