Class: Codeowners::Storage::Collection
- Inherits:
-
Object
- Object
- Codeowners::Storage::Collection
- Defined in:
- lib/codeowners/storage/collection.rb
Instance Method Summary collapse
- #dump ⇒ Object
- #find(&blk) ⇒ Object
- #find_all(&blk) ⇒ Object
-
#initialize(collection) ⇒ Collection
constructor
A new instance of Collection.
- #upsert(*records) ⇒ Object
Constructor Details
#initialize(collection) ⇒ Collection
Returns a new instance of Collection.
6 7 8 9 10 |
# File 'lib/codeowners/storage/collection.rb', line 6 def initialize(collection) @collection = collection.each_with_object({}) do |record, memo| memo[record.fetch("id")] = record end end |
Instance Method Details
#dump ⇒ Object
28 29 30 |
# File 'lib/codeowners/storage/collection.rb', line 28 def dump collection.values.dup end |
#find(&blk) ⇒ Object
12 13 14 |
# File 'lib/codeowners/storage/collection.rb', line 12 def find(&blk) collection.values.find(&blk) end |
#find_all(&blk) ⇒ Object
16 17 18 |
# File 'lib/codeowners/storage/collection.rb', line 16 def find_all(&blk) collection.values.find_all(&blk) end |
#upsert(*records) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/codeowners/storage/collection.rb', line 20 def upsert(*records) records = Array(records).flatten records.each do |record| collection[record.fetch(:id)] = record end end |