Class: Cash::Mock

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/cash/mock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serversObject

Returns the value of attribute servers.



3
4
5
# File 'lib/cash/mock.rb', line 3

def servers
  @servers
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/cash/mock.rb', line 13

def [](key)
  deep_clone(super(key))
end

#[]=(key, value) ⇒ Object



9
10
11
# File 'lib/cash/mock.rb', line 9

def []=(key, value)
  super(key, deep_clone(value))
end

#add(key, value, *options) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/cash/mock.rb', line 35

def add(key, value, *options)
  if self[key]
    "NOT_STORED\r\n"
  else
    self[key] = value
    "STORED\r\n"
  end
end

#append(key, value) ⇒ Object



48
49
50
# File 'lib/cash/mock.rb', line 48

def append(key, value)
  set(key, get(key).to_s + value.to_s)
end

#decr(key, amount = 1) ⇒ Object



30
31
32
33
# File 'lib/cash/mock.rb', line 30

def decr(key, amount = 1)
  self[key] ||= 0
  self[key] -= amount
end

#delete(key, *options) ⇒ Object



44
45
46
# File 'lib/cash/mock.rb', line 44

def delete(key, *options)
  self[key] = nil
end

#flush_allObject



56
57
58
# File 'lib/cash/mock.rb', line 56

def flush_all
  clear
end

#get(key, *args) ⇒ Object



21
22
23
# File 'lib/cash/mock.rb', line 21

def get(key, *args)
  self[key]
end

#get_multi(*values) ⇒ Object



5
6
7
# File 'lib/cash/mock.rb', line 5

def get_multi(*values)
  reject { |k,v| !values.include? k }
end

#incr(key, amount = 1) ⇒ Object



25
26
27
28
# File 'lib/cash/mock.rb', line 25

def incr(key, amount = 1)
  self[key] ||= 0
  self[key] += amount
end

#namespaceObject



52
53
54
# File 'lib/cash/mock.rb', line 52

def namespace
  nil
end

#reset_runtimeObject



64
65
66
# File 'lib/cash/mock.rb', line 64

def reset_runtime
  [0, Hash.new(0)]
end

#set(key, value, *options) ⇒ Object



17
18
19
# File 'lib/cash/mock.rb', line 17

def set(key, value, *options)
  self[key] = value
end

#statsObject



60
61
62
# File 'lib/cash/mock.rb', line 60

def stats
  {}
end