Class: DB
- Inherits:
-
Object
- Object
- DB
- Defined in:
- lib/sacrifice/db.rb
Overview
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.
Class Method Summary collapse
Class Method Details
.[](arg) ⇒ Object
8 9 10 11 12 13 |
# 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 ⇒ Object
25 26 27 |
# File 'lib/sacrifice/db.rb', line 25 def filename @filename || File.join(ENV['HOME'], '.sacrificerc') end |
.filename=(f) ⇒ Object
29 30 31 32 |
# File 'lib/sacrifice/db.rb', line 29 def filename=(f) @cached_yaml = nil @filename = f end |
.update {|data| ... } ⇒ Object
15 16 17 18 19 20 21 22 23 |
# 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 |