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.

Parameters:

  • db_file (String)


12
13
14
# File 'lib/dyndnsd/database.rb', line 12

def initialize(db_file)
  @db_file = db_file
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/dyndnsd/database.rb', line 35

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

#loadvoid

This method returns an undefined value.



17
18
19
20
21
22
23
24
# File 'lib/dyndnsd/database.rb', line 17

def load
  if File.file?(@db_file)
    @db = JSON.parse(File.read(@db_file, mode: 'r'))
  else
    @db = {}
  end
  @db_hash = @db.hash
end

#savevoid

This method returns an undefined value.



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

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