Class: Symian::YAMLBackend
- Inherits:
-
MemoryBackend
- Object
- MemoryBackend
- Symian::YAMLBackend
- Defined in:
- lib/symian/trace_collector.rb
Instance Method Summary collapse
-
#initialize(filename) ⇒ YAMLBackend
constructor
A new instance of YAMLBackend.
- #save_and_close ⇒ Object
Constructor Details
#initialize(filename) ⇒ YAMLBackend
Returns a new instance of YAMLBackend.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/symian/trace_collector.rb', line 79 def initialize(filename) @filename = filename # if file exists and is non-empty, try to read its contents size = File.size?(@filename) if !size.nil? and size > 0 hash = File.open(@filename) do |file| YAML.load(file) end TraceCollector::ATTRIBUTES.map(&:to_s).each do |attr| instance_variable_set("@#{attr}_storage", hash[attr]) end else super() end end |
Instance Method Details
#save_and_close ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/symian/trace_collector.rb', line 95 def save_and_close hash = {} TraceCollector::ATTRIBUTES.map(&:to_s).each do |attr| hash[attr] = instance_variable_get("@#{attr}_storage") end File.open(@filename, 'w') do |file| YAML.dump(hash, file) end end |