Class: ScoutApm::LayawayFile
- Inherits:
-
Object
- Object
- ScoutApm::LayawayFile
- Defined in:
- lib/scout_apm/layaway_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #deserialize(data) ⇒ Object
-
#initialize(path) ⇒ LayawayFile
constructor
A new instance of LayawayFile.
- #load ⇒ Object
- #read_raw(f) ⇒ Object
- #serialize(data) ⇒ Object
- #write(data) ⇒ Object
- #write_raw(f, data) ⇒ Object
Constructor Details
#initialize(path) ⇒ LayawayFile
Returns a new instance of LayawayFile.
6 7 8 |
# File 'lib/scout_apm/layaway_file.rb', line 6 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/scout_apm/layaway_file.rb', line 4 def path @path end |
Instance Method Details
#deserialize(data) ⇒ Object
29 30 31 |
# File 'lib/scout_apm/layaway_file.rb', line 29 def deserialize(data) Marshal.load(data) end |
#load ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/scout_apm/layaway_file.rb', line 10 def load data = File.open(path, "r") { |f| read_raw(f) } deserialize(data) rescue NameError, ArgumentError, TypeError => e # Marshal error ScoutApm::Agent.instance.logger.info("Unable to load data from Layaway file, resetting.") ScoutApm::Agent.instance.logger.debug("#{e.}, #{e.backtrace.join("\n\t")}") nil end |
#read_raw(f) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/scout_apm/layaway_file.rb', line 33 def read_raw(f) contents = "" while true contents << f.read_nonblock(10_000) end rescue Errno::EAGAIN, Errno::EINTR IO.select([f]) retry rescue EOFError contents end |
#serialize(data) ⇒ Object
25 26 27 |
# File 'lib/scout_apm/layaway_file.rb', line 25 def serialize(data) Marshal.dump(data) end |
#write(data) ⇒ Object
20 21 22 23 |
# File 'lib/scout_apm/layaway_file.rb', line 20 def write(data) serialized_data = serialize(data) File.open(path, "w") { |f| write_raw(f, serialized_data) } end |
#write_raw(f, data) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/scout_apm/layaway_file.rb', line 45 def write_raw(f, data) result = 0 while (result < data.length) result += f.write_nonblock(data) end rescue Errno::EAGAIN, Errno::EINTR IO.select(nil, [f]) retry end |