Class: Bandit::MemoryStorage
- Inherits:
-
BaseStorage
- Object
- BaseStorage
- Bandit::MemoryStorage
- Defined in:
- lib/bandit/storage/memory.rb
Instance Method Summary collapse
- #clear! ⇒ Object
-
#get(key, default = 0) ⇒ Object
get key if exists, otherwise 0.
-
#incr(key, count = 1) ⇒ Object
increment key by count.
-
#init(key, value) ⇒ Object
initialize key if not set.
-
#initialize(config) ⇒ MemoryStorage
constructor
A new instance of MemoryStorage.
-
#set(key, value) ⇒ Object
set key with value, regardless of whether it is set or not.
Methods inherited from BaseStorage
#alt_started_key, #alternative_start_time, #conv_key, #conversion_count, get_storage, #incr_conversions, #incr_participants, #make_key, #part_key, #participant_count, #player_state_get, #player_state_key, #player_state_set, #with_failure_grace
Constructor Details
#initialize(config) ⇒ MemoryStorage
Returns a new instance of MemoryStorage.
3 4 5 |
# File 'lib/bandit/storage/memory.rb', line 3 def initialize(config) @memory = Hash.new nil end |
Instance Method Details
#clear! ⇒ Object
27 28 29 |
# File 'lib/bandit/storage/memory.rb', line 27 def clear! @memory = Hash.new nil end |
#get(key, default = 0) ⇒ Object
get key if exists, otherwise 0
18 19 20 |
# File 'lib/bandit/storage/memory.rb', line 18 def get(key, default=0) @memory.fetch(key, default) end |
#incr(key, count = 1) ⇒ Object
increment key by count
8 9 10 |
# File 'lib/bandit/storage/memory.rb', line 8 def incr(key, count=1) @memory[key] = get(key) + count end |
#init(key, value) ⇒ Object
initialize key if not set
13 14 15 |
# File 'lib/bandit/storage/memory.rb', line 13 def init(key, value) @memory[key] = value if @memory[key].nil? end |
#set(key, value) ⇒ Object
set key with value, regardless of whether it is set or not
23 24 25 |
# File 'lib/bandit/storage/memory.rb', line 23 def set(key, value) @memory[key] = value end |