class Del::Repository

This class is a facade for backend data storage.

Public Class Methods

new(storage: {}, mapper:) click to toggle source
# File lib/del/repository.rb, line 6
def initialize(storage: {}, mapper:)
  @storage = storage
  @mapper = mapper
  @lock = Mutex.new
end

Public Instance Methods

[](id) click to toggle source
# File lib/del/repository.rb, line 12
def [](id)
  find(id)
end
all() click to toggle source
# File lib/del/repository.rb, line 22
def all
  @lock.synchronize do
    @storage.map do |(_, value)|
      @mapper.map_from(value)
    end
  end
end
find(id) click to toggle source
# File lib/del/repository.rb, line 16
def find(id)
  @lock.synchronize do
    @mapper.map_from(@storage[id.to_s])
  end
end
upsert(id, attributes = {}) click to toggle source
# File lib/del/repository.rb, line 30
def upsert(id, attributes = {})
  @lock.synchronize do
    @storage[id.to_s] = attributes
  end
end