Class: Scout::DataFile
- Inherits:
-
Object
- Object
- Scout::DataFile
- Defined in:
- lib/scout/data_file.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path, logger) ⇒ DataFile
constructor
A new instance of DataFile.
-
#save(content) ⇒ Object
saves the data file by (1) locking the file at
path
to ensure other processes don’t overlap (2) using an atomic write to ensure other processes always read a complete file. -
#tmp_path ⇒ Object
atomic_write first writes to the tmp file.
Constructor Details
#initialize(path, logger) ⇒ DataFile
Returns a new instance of DataFile.
7 8 9 10 |
# File 'lib/scout/data_file.rb', line 7 def initialize(path,logger) @path = path @logger = logger end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/scout/data_file.rb', line 5 def data @data end |
#logger ⇒ Object
Returns the value of attribute logger.
4 5 6 |
# File 'lib/scout/data_file.rb', line 4 def logger @logger end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/scout/data_file.rb', line 4 def path @path end |
Instance Method Details
#save(content) ⇒ Object
saves the data file by (1) locking the file at path
to ensure other processes don’t overlap (2) using an atomic write to ensure other processes always read a complete file.
19 20 21 22 23 |
# File 'lib/scout/data_file.rb', line 19 def save(content) lock do atomic_write(content) end end |
#tmp_path ⇒ Object
atomic_write first writes to the tmp file.
13 14 15 |
# File 'lib/scout/data_file.rb', line 13 def tmp_path path+'.tmp' end |