lib/dyndnsd/database.rb in dyndnsd-1.6.1 vs lib/dyndnsd/database.rb in dyndnsd-2.0.0.rc1
- old
+ new
@@ -2,30 +2,32 @@
require 'forwardable'
module Dyndnsd
class Database
extend Forwardable
-
+
def_delegators :@db, :[], :[]=, :each, :has_key?
-
+
def initialize(db_file)
@db_file = db_file
end
-
+
def load
if File.file?(@db_file)
- @db = JSON.load(File.open(@db_file, 'r') { |f| f.read })
+ @db = JSON.parse(File.open(@db_file, 'r', &:read))
else
@db = {}
end
@db_hash = @db.hash
end
-
+
def save
- File.open(@db_file, 'w') { |f| JSON.dump(@db, f) }
- @db_hash = @db.hash
+ Helper.span('database_save') do |_span|
+ File.open(@db_file, 'w') { |f| JSON.dump(@db, f) }
+ @db_hash = @db.hash
+ end
end
-
+
def changed?
@db_hash != @db.hash
end
end
end