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.10.0 lib/dyndnsd/database.rb
dyndnsd-3.9.2 lib/dyndnsd/database.rb
dyndnsd-3.9.1 lib/dyndnsd/database.rb
dyndnsd-3.9.0 lib/dyndnsd/database.rb
dyndnsd-3.8.2 lib/dyndnsd/database.rb
dyndnsd-3.8.1 lib/dyndnsd/database.rb
dyndnsd-3.8.0 lib/dyndnsd/database.rb
dyndnsd-3.7.3 lib/dyndnsd/database.rb
dyndnsd-3.7.2 lib/dyndnsd/database.rb
dyndnsd-3.7.1 lib/dyndnsd/database.rb
dyndnsd-3.7.0 lib/dyndnsd/database.rb
dyndnsd-3.6.2 lib/dyndnsd/database.rb
dyndnsd-3.6.1 lib/dyndnsd/database.rb
dyndnsd-3.6.0 lib/dyndnsd/database.rb
dyndnsd-3.5.3 lib/dyndnsd/database.rb
dyndnsd-3.5.2 lib/dyndnsd/database.rb
dyndnsd-3.5.1 lib/dyndnsd/database.rb
dyndnsd-3.5.0 lib/dyndnsd/database.rb
dyndnsd-3.4.8 lib/dyndnsd/database.rb
dyndnsd-3.4.7 lib/dyndnsd/database.rb