44 lines
815 B
Ruby
44 lines
815 B
Ruby
# This is a non thread safe replacement for the
|
|
# couchbase counter mechanism since every test needs
|
|
# a clean start and Hash#clear is soooo much faster than
|
|
# a couchbase bucket flush
|
|
class InMemoryQCounter
|
|
attr_reader :store
|
|
|
|
def initialize
|
|
@store = {}
|
|
end
|
|
|
|
def get(key, options = {})
|
|
store[key]
|
|
end
|
|
|
|
def set(key, value)
|
|
store[key] = value
|
|
end
|
|
|
|
def incr(key, options = {})
|
|
# store[key] ||= options[:initial].to_i
|
|
# store[key] += 1
|
|
if store[key]
|
|
store[key] += 1
|
|
else
|
|
store[key] = options[:initial].to_i
|
|
end
|
|
end
|
|
|
|
def decr(key, options = {})
|
|
# store[key] ||= options[:initial].to_i
|
|
# store[key] -= 1
|
|
if store[key]
|
|
store[key] -= 1
|
|
else
|
|
store[key] = options[:initial].to_i
|
|
end
|
|
end
|
|
|
|
def flush
|
|
store.clear
|
|
end
|
|
end
|