Sha256: 37f790b9babe3e49a094a34cfdcf2d69e2da0b28f9c14b43e2919b07a2124640

Contents?: true

Size: 581 Bytes

Versions: 8

Compression:

Stored size: 581 Bytes

Contents

module Del
  class Repository
    def initialize(storage = {})
      @storage = storage
      @lock = Mutex.new
    end

    def [](id)
      find_by(id)
    end

    def find_by(id)
      @lock.synchronize { @storage[id.to_s] }
    end

    def find_by_value
      @lock.synchronize { @storage.values.find { |x| yield x } }
    end

    def find_all
      @lock.synchronize { @storage.keys }
    end

    def upsert(id, attributes = {})
      Del.logger.debug([id, attributes].inspect)
      @lock.synchronize do
        @storage[id.to_s] = attributes
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
del-0.1.13 lib/del/repository.rb
del-0.1.12 lib/del/repository.rb
del-0.1.11 lib/del/repository.rb
del-0.1.10 lib/del/repository.rb
del-0.1.9 lib/del/repository.rb
del-0.1.8 lib/del/repository.rb
del-0.1.7 lib/del/repository.rb
del-0.1.6 lib/del/repository.rb