1
0
mirror of https://github.com/cmur2/dyndnsd.git synced 2026-04-03 02:18:29 +02:00
This commit is contained in:
cn
2013-04-27 14:07:14 +02:00
commit 755a448174
18 changed files with 615 additions and 0 deletions

32
lib/dyndnsd/database.rb Normal file
View File

@@ -0,0 +1,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 })
else
@db = {}
end
@db_hash = @db.hash
end
def save
File.open(@db_file, 'w') { |f| JSON.dump(@db, f) }
@db_hash = @db.hash
end
def changed?
@db_hash != @db.hash
end
end
end