Sha256: 9bd71748cc302ae435b9c9f62781ded357d3f7010cf2a769f12d1dc9ad009290

Contents?: true

Size: 562 Bytes

Versions: 14

Compression:

Stored size: 562 Bytes

Contents

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dyndnsd-1.6.1 lib/dyndnsd/database.rb
dyndnsd-1.6.0 lib/dyndnsd/database.rb
dyndnsd-1.5.0 lib/dyndnsd/database.rb
dyndnsd-1.4.0 lib/dyndnsd/database.rb
dyndnsd-1.3.0 lib/dyndnsd/database.rb
dyndnsd-1.2.2 lib/dyndnsd/database.rb
dyndnsd-1.2.1 lib/dyndnsd/database.rb
dyndnsd-1.2.0 lib/dyndnsd/database.rb
dyndnsd-1.1.0 lib/dyndnsd/database.rb
dyndnsd-1.0.0 lib/dyndnsd/database.rb
dyndnsd-0.0.4 lib/dyndnsd/database.rb
dyndnsd-0.0.3 lib/dyndnsd/database.rb
dyndnsd-0.0.2 lib/dyndnsd/database.rb
dyndnsd-0.0.1 lib/dyndnsd/database.rb