Sha256: 6d247f2c6b9f20a3f67b488ba48a717beed8166d01af242137aa93b6e515f6eb

Contents?: true

Size: 598 Bytes

Versions: 3

Compression:

Stored size: 598 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.parse(File.open(@db_file, 'r', &:read))
      else
        @db = {}
      end
      @db_hash = @db.hash
    end

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dyndnsd-2.0.0 lib/dyndnsd/database.rb
dyndnsd-2.0.0.rc2 lib/dyndnsd/database.rb
dyndnsd-2.0.0.rc1 lib/dyndnsd/database.rb