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



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

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

#each(&block) ⇒ Object



181
182
183
184
185
186
187
188
189
# File 'lib/dato/local/items_repo.rb', line 181

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



199
200
201
# File 'lib/dato/local/items_repo.rb', line 199

def keys
  map(&:id)
end

#valuesObject



203
204
205
# File 'lib/dato/local/items_repo.rb', line 203

def values
  to_a
end