class DB
This is about the dumbest DB
you can get. It’s a hash that knows how to serialize itself. Dumb, but it gets the job done.
Public Class Methods
[](arg)
click to toggle source
# File lib/sacrifice/db.rb, line 8 def [](arg) # FIXME deep-freeze this; shallow freezing is insufficient result = yaml[arg] result.freeze result end
filename()
click to toggle source
# File lib/sacrifice/db.rb, line 25 def filename @filename || File.join(ENV['HOME'], '.sacrificerc') end
filename=(f)
click to toggle source
# File lib/sacrifice/db.rb, line 29 def filename=(f) @cached_yaml = nil @filename = f end
update() { |data| ... }
click to toggle source
# File lib/sacrifice/db.rb, line 15 def update @cached_yaml = nil data = _yaml yield data # do this *before* blowing away the db data_as_yaml = data.to_yaml File.open(filename, 'w') { |f| f.write(data_as_yaml) } end
Private Class Methods
_yaml()
click to toggle source
# File lib/sacrifice/db.rb, line 40 def _yaml if File.exist?(filename) YAML.load_file(filename) || {} else {} end end
yaml()
click to toggle source
# File lib/sacrifice/db.rb, line 36 def yaml @cached_yaml ||= _yaml end