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