Class: Metricstore::MockKeyValueClient

Inherits:
Object
  • Object
show all
Defined in:
lib/metricstore/mock_key_value_client.rb

Overview

Internal class. Use this class outside the gem at your own risk. TTL is ignored. Not thread-safe. For testing purposes only.

Instance Method Summary collapse

Constructor Details

#initialize(*args, &callback) ⇒ MockKeyValueClient

Returns a new instance of MockKeyValueClient.



6
7
8
# File 'lib/metricstore/mock_key_value_client.rb', line 6

def initialize(*args, &callback)
  @store = {}
end

Instance Method Details

#add(key, value, opts = {}) ⇒ Object



19
20
21
22
23
# File 'lib/metricstore/mock_key_value_client.rb', line 19

def add(key, value, opts={})
  return nil if @store.include?(key)
  @store[key] = value
  [value, value]
end

#fetch(key, opts = {}) ⇒ Object



30
31
32
33
# File 'lib/metricstore/mock_key_value_client.rb', line 30

def fetch(key, opts={})
  value = @store[key]
  value.nil? ? nil : [value, value]
end

#increment(key, delta, opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/metricstore/mock_key_value_client.rb', line 10

def increment(key, delta, opts={})
  if @store.include?(key)
    @store[key] += delta
  else
    @store[key] = delta
  end
  [@store[key], @store[key]]
end

#set(key, value, opts = {}) ⇒ Object



25
26
27
28
# File 'lib/metricstore/mock_key_value_client.rb', line 25

def set(key, value, opts={})
  return nil if opts[:cas] && opts[:cas] != @store[key]
  @store[key] = value
end

#to_sObject



35
36
37
# File 'lib/metricstore/mock_key_value_client.rb', line 35

def to_s
  "MockKeyValueClient: #{@store.inspect}"
end