Class: Kameleoon::DataManager::DataMapStorage
- Inherits:
-
Object
- Object
- Kameleoon::DataManager::DataMapStorage
- Defined in:
- lib/kameleoon/data/manager/data_map_storage.rb
Overview
DataMapStorage is a readonly accessor to a key-value based storage of specific visitor data. It is thread-safe
Instance Method Summary collapse
- #enumerate(&blk) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(mutex, map) ⇒ DataMapStorage
constructor
A new instance of DataMapStorage.
- #size ⇒ Object
Constructor Details
#initialize(mutex, map) ⇒ DataMapStorage
Returns a new instance of DataMapStorage.
9 10 11 12 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 9 def initialize(mutex, map) @mutex = mutex @map = map end |
Instance Method Details
#enumerate(&blk) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 14 def enumerate(&blk) return if @map.nil? @mutex.with_read_lock do @map.each { |_k, v| blk.call(v) } end end |
#get(key) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 22 def get(key) return nil if @map.nil? value = nil @mutex.with_read_lock do value = @map[key] end value end |
#size ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 32 def size return 0 if @map.nil? value = nil @mutex.with_read_lock do value = @map.size end value end |