Class: Dyndnsd::Database
- Inherits:
-
Object
- Object
- Dyndnsd::Database
- Extended by:
- Forwardable
- Defined in:
- lib/dyndnsd/database.rb
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#initialize(db_file) ⇒ Database
constructor
A new instance of Database.
- #load ⇒ Object
- #save ⇒ Object
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
28 29 30 |
# File 'lib/dyndnsd/database.rb', line 28 def changed? @db_hash != @db.hash end |
#load ⇒ Object
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 |
#save ⇒ Object
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 |