Class: Symian::YAMLBackend

Inherits:
MemoryBackend show all
Defined in:
lib/symian/trace_collector.rb

Instance Method Summary collapse

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_closeObject



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