lib/pdk/answer_file.rb
def read_from_disk
      return {} if !PDK::Util::Filesystem.file?(answer_file_path) || PDK::Util::Filesystem.zero?(answer_file_path)

      unless PDK::Util::Filesystem.readable?(answer_file_path)
        raise PDK::CLI::FatalError, _("Unable to open '%{file}' for reading") % {
          file: answer_file_path,
        }
      end

      answers = JSON.parse(PDK::Util::Filesystem.read_file(answer_file_path))
      if answers.is_a?(Hash)
        answers
      else
        PDK.logger.warn _("Answer file '%{path}' did not contain a valid set of answers, recreating it") % {
          path: answer_file_path,
        }
        {}
      end
    rescue JSON::JSONError
      PDK.logger.warn _("Answer file '%{path}' did not contain valid JSON, recreating it") % {
        path: answer_file_path,
      }
      {}
    end
# Read existing answers into memory from the answer file on disk.
#
# @raise [PDK::CLI::FatalError] If the answer file exists but can not be
#   read.
#
# @return [Hash{String => Object}] The existing questions and answers.
Read existing answers into memory from the answer file on disk.
Read existing answers into memory from the answer file on disk .
def read_from_disk
      return {} if !PDK::Util::Filesystem.file?(answer_file_path) || PDK::Util::Filesystem.zero?(answer_file_path)
      unless PDK::Util::Filesystem.readable?(answer_file_path)
        raise PDK::CLI::FatalError, _("Unable to open '%{file}' for reading") % {
          file: answer_file_path,
        }
      end
      answers = JSON.parse(PDK::Util::Filesystem.read_file(answer_file_path))
      if answers.is_a?(Hash)
        answers
      else
        PDK.logger.warn _("Answer file '%{path}' did not contain a valid set of answers, recreating it") % {
          path: answer_file_path,
        }
        {}
      end
    rescue JSON::JSONError
      PDK.logger.warn _("Answer file '%{path}' did not contain valid JSON, recreating it") % {
        path: answer_file_path,
      }
      {}
    end
def read_from_disk return { } if ! PDK :: Util :: Filesystem . file? ( answer_file_path ) || PDK :: Util :: Filesystem . zero? ( answer_file_path ) unless PDK :: Util :: Filesystem . readable? ( answer_file_path ) raise PDK :: CLI :: FatalError , _ ( "Unable to open '%{file}' for reading" ) % { file : answer_file_path , } end answers = JSON . parse ( PDK :: Util :: Filesystem . read_file ( answer_file_path ) ) if answers . is_a? ( Hash ) answers else PDK . logger . warn _ ( "Answer file '%{path}' did not contain a valid set of answers, recreating it" ) % { path : answer_file_path , } { } end rescue JSON :: JSONError PDK . logger . warn _ ( "Answer file '%{path}' did not contain valid JSON, recreating it" ) % { path : answer_file_path , } { } end
Read existing answers into memory from the answer file on disk.
Read existing answers into memory from the answer file on disk .
The existing questions and answers.
The existing questions and answers .
Hash{String => Object}
[PDK::CLI::FatalError] If the answer file exists but can not be read.
[ PDK :: CLI :: FatalError ] If the answer file exists but can not be read .