Class: Dato::Local::ItemsRepo::ItemCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/dato/local/items_repo.rb

Instance Method Summary collapse

Methods inherited from Array

#deep_stringify_keys

Instance Method Details

#[](id) ⇒ Object



198
199
200
201
202
203
204
# File 'lib/dato/local/items_repo.rb', line 198

def [](id)
  if id.is_a? String
    find { |item| item.id == id }
  else
    super(id)
  end
end

#each(&block) ⇒ Object



188
189
190
191
192
193
194
195
196
# File 'lib/dato/local/items_repo.rb', line 188

def each(&block)
  if block && block.arity == 2
    each_with_object({}) do |item, acc|
      acc[item.id] = item
    end.each(&block)
  else
    super(&block)
  end
end

#keysObject



206
207
208
# File 'lib/dato/local/items_repo.rb', line 206

def keys
  map(&:id)
end

#valuesObject



210
211
212
# File 'lib/dato/local/items_repo.rb', line 210

def values
  to_a
end