Class: Dyndnsd::Database

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dyndnsd/database.rb

Instance Method Summary collapse

Constructor Details

#initialize(db_file) ⇒ Database

Returns a new instance of Database.



10
11
12
# File 'lib/dyndnsd/database.rb', line 10

def initialize(db_file)
  @db_file = db_file
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dyndnsd/database.rb', line 28

def changed?
  @db_hash != @db.hash
end

#loadObject



14
15
16
17
18
19
20
21
# File 'lib/dyndnsd/database.rb', line 14

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

#saveObject



23
24
25
26
# File 'lib/dyndnsd/database.rb', line 23

def save
  File.open(@db_file, 'w') { |f| JSON.dump(@db, f) }
  @db_hash = @db.hash
end