Sha256: c7334735d631a79781c942e440d444b079e7194c2d945362e2e93eb4a72053f0

Contents?: true

Size: 722 Bytes

Versions: 42

Compression:

Stored size: 722 Bytes

Contents

# frozen_string_literal: true

require 'forwardable'

module Dyndnsd
  class Database
    extend Forwardable

    def_delegators :@db, :[], :[]=, :each, :has_key?

    # @param db_file [String]
    def initialize(db_file)
      @db_file = db_file
    end

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

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

    # @return [Boolean]
    def changed?
      @db_hash != @db.hash
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
dyndnsd-3.4.6 lib/dyndnsd/database.rb
dyndnsd-3.4.5 lib/dyndnsd/database.rb
dyndnsd-3.4.4 lib/dyndnsd/database.rb
dyndnsd-3.4.3 lib/dyndnsd/database.rb
dyndnsd-3.4.2 lib/dyndnsd/database.rb
dyndnsd-3.4.1 lib/dyndnsd/database.rb
dyndnsd-3.4.0 lib/dyndnsd/database.rb
dyndnsd-3.3.3 lib/dyndnsd/database.rb
dyndnsd-3.3.2 lib/dyndnsd/database.rb
dyndnsd-3.3.2.rc1 lib/dyndnsd/database.rb
dyndnsd-3.3.1 lib/dyndnsd/database.rb
dyndnsd-3.3.0 lib/dyndnsd/database.rb
dyndnsd-3.2.0 lib/dyndnsd/database.rb
dyndnsd-3.1.3 lib/dyndnsd/database.rb
dyndnsd-3.1.2 lib/dyndnsd/database.rb
dyndnsd-3.1.1 lib/dyndnsd/database.rb
dyndnsd-3.1.0 lib/dyndnsd/database.rb
dyndnsd-3.1.0.rc1 lib/dyndnsd/database.rb
dyndnsd-3.0.0 lib/dyndnsd/database.rb
dyndnsd-2.3.1 lib/dyndnsd/database.rb