Sha256: 0d13d9d9ead0e43cecadebca312e2a1fd03d325f963b830aab3a4edb5e6d25d2
Contents?: true
Size: 1.32 KB
Versions: 8
Compression:
Stored size: 1.32 KB
Contents
require "yaml/store" module FakeSQS class FileDatabase attr_reader :filename def initialize(filename) @filename = filename @queue_objects = {} end def load transaction do store["queues"] ||= {} end end def transaction store.transaction do yield end end def reset transaction do store["queues"] = {} end @queue_objects = {} end def []=(key, value) storage[key] = value.to_yaml end def [](key) value = storage[key] if value deserialize(key) else value end end def each(&block) storage.each do |key, value| yield key, deserialize(key) end end def select(&block) new_list = storage.select do |key, value| yield key, deserialize(key) end Hash[new_list.map { |key, value| [key, deserialize(key)] }] end def delete(key) storage.delete(key) end def values storage.map { |key, value| deserialize(key) } end private def deserialize(key) @queue_objects[key] ||= Queue.new(storage[key].merge(message_factory: Message)) end def storage store["queues"] end def store @store ||= YAML::Store.new(filename) end end end
Version data entries
8 entries across 8 versions & 1 rubygems