Class: Scout::DataFile

Inherits:
Object
  • Object
show all
Defined in:
lib/scout/data_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/scout/data_file.rb', line 5

def data
  @data
end

#loggerObject

Returns the value of attribute logger.



4
5
6
# File 'lib/scout/data_file.rb', line 4

def logger
  @logger
end

#pathObject

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_pathObject

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