lib/heliodor/db.rb in heliodor-0.2.1 vs lib/heliodor/db.rb in heliodor-0.2.2

- old
+ new

@@ -17,22 +17,19 @@ 'ruby_platform' => RUBY_PLATFORM } } @file = File.expand_path(file.to_s) if File.exist?(@file) - Zlib::GzipReader.open(File.expand_path(@file)) do |f| - bb = BSON::ByteBuffer.new(f.read) - @dat = Hash.from_bson(bb) - f.close - end + f = Zlib::GzipReader.open(File.expand_path(@file)) + bb = BSON::ByteBuffer.new(f.read) + @dat = Hash.from_bson(bb) + f.close else - Zlib::GzipWriter.open(File.expand_path(@file)) do |f| - # File.open(@file, 'w') do |f| - f.write(@dtable.to_bson.to_s) - @dat = @dtable.clone - f.close - end + f = Zlib::GzipWriter.open(File.expand_path(@file)) + f.write(@dtable.to_bson.to_s) + @dat = @dtable.clone + f.close end end # Entry point for building queries # @param table [String] @@ -52,21 +49,21 @@ # @return [self] def delete(table) if @tsafe @mutex.synchronize do @dat.delete(table) - write(dat) + write(@dat) end else - write(dat) + write(@dat) @dat.delete(table) end end # Returns array of table names # @return [Array<String>] Array of table names def tables - Hash.from_bson(BSON::ByteBuffer.new(File.read(@file))).keys + @dat.keys end # Writes database to file # @return [self] def write(dat)