Class: DataContainer
- Inherits:
-
Object
show all
- Includes:
- Assert
- Defined in:
- lib/common/datastorage.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Assert
assert, #assert, assert_nil, #assert_nil, #assert_not_nil, assert_not_nil, raise_exception
Constructor Details
#initialize(key, data, persistentStorageHandler) ⇒ DataContainer
Returns a new instance of DataContainer.
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/common/datastorage.rb', line 191
def initialize( key, data, persistentStorageHandler )
assert_not_nil( key, "key" )
assert_not_nil( data, "data" )
assert_not_nil( persistentStorageHandler, "persistentStorageHandler" )
@key = key
@data = data
@persistentStorage = persistentStorageHandler
@fileName = nil
@inMemory = true
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
188
189
190
|
# File 'lib/common/datastorage.rb', line 188
def key
@key
end
|
Instance Method Details
#clear ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/common/datastorage.rb', line 225
def clear
if ( @fileName != nil )
@persistentStorage.delete_file( build_file_name )
@fileName = nil
end
@data = nil
@key = nil
@persistentStorage = nil
@inMemory = false
end
|
#data ⇒ Object
204
205
206
207
208
209
210
211
212
|
# File 'lib/common/datastorage.rb', line 204
def data
if ( data_in_memory? )
return @data
end
@data = Marshal.load( @persistentStorage.load_file( build_file_name ) )
@inMemory = true
return @data
end
|
#data=(newData) ⇒ Object
215
216
217
218
219
220
221
222
|
# File 'lib/common/datastorage.rb', line 215
def data=( newData )
@data = newData
if ( @fileName != nil )
@persistentStorage.delete_file( build_file_name )
@fileName = nil
end
@inMemory = true
end
|
#data_in_memory? ⇒ Boolean
248
249
250
|
# File 'lib/common/datastorage.rb', line 248
def data_in_memory?
return @inMemory
end
|
#move_to_storage ⇒ Object
238
239
240
241
242
243
244
|
# File 'lib/common/datastorage.rb', line 238
def move_to_storage
if ( data_in_memory? )
@persistentStorage.write_file( build_file_name, Marshal.dump( @data ) )
@data = nil
@inMemory = false
end
end
|