Sha256: 057a9a24c18ccac38af43228f9e9055f3979405746ee3de4a70f6e36547c3441
Contents?: true
Size: 653 Bytes
Versions: 3
Compression:
Stored size: 653 Bytes
Contents
# frozen_string_literal: true module Del # This class is a facade for backend data storage. class Repository def initialize(storage: {}, mapper:) @storage = storage @mapper = mapper @lock = Mutex.new end def [](id) find(id) end def find(id) @lock.synchronize do @mapper.map_from(@storage[id.to_s]) end end def all @lock.synchronize do @storage.map do |(_, value)| @mapper.map_from(value) end end end def upsert(id, attributes = {}) @lock.synchronize do @storage[id.to_s] = attributes end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
del-0.1.19 | lib/del/repository.rb |
del-0.1.18 | lib/del/repository.rb |
del-0.1.17 | lib/del/repository.rb |