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
- #to_s ⇒ Object
Constructor Details
#initialize(mutex, map) ⇒ DataMapStorage
Returns a new instance of DataMapStorage.
16 17 18 19 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 16 def initialize(mutex, map) @mutex = mutex @map = map end |
Instance Method Details
#enumerate(&blk) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 21 def enumerate(&blk) return if @map.nil? @mutex.with_read_lock do @map.each { |_k, v| blk.call(v) } end end |
#get(key) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 29 def get(key) return nil if @map.nil? value = nil @mutex.with_read_lock do value = @map[key] end value end |
#size ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 39 def size return 0 if @map.nil? value = nil @mutex.with_read_lock do value = @map.size end value end |
#to_s ⇒ Object
10 11 12 13 14 |
# File 'lib/kameleoon/data/manager/data_map_storage.rb', line 10 def to_s values = [] enumerate { |v| values << v } "DataMapStorage{values:#{values.join(',')}}" end |