Class: Imap::Backup::CLI::Local::Check

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/imap/backup/cli/local/check.rb

Overview

Runs integrity check on local backups

Constant Summary

Constants included from Helpers

Helpers::NAMESPACE_CONFIGURATION_DESCRIPTION

Instance Method Summary collapse

Methods included from Helpers

#account, included, #load_config, #requested_accounts

Constructor Details

#initialize(options) ⇒ Check

Returns a new instance of Check.

Parameters:

  • options (Hash)

    CLI options controlling output

  • opts (Hash)

    a customizable set of options



22
23
24
# File 'lib/imap/backup/cli/local/check.rb', line 22

def initialize(options)
  @options = options
end

Instance Method Details

#runvoid

This method returns an undefined value.

Runs the check



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/imap/backup/cli/local/check.rb', line 28

def run
  results = requested_accounts(config).map do ||
    serialized_folders = ::SerializedFolders.new(account: )
    folder_results = serialized_folders.map do |serializer, _folder|
      serializer.check_integrity!
      {name: serializer.folder, result: "OK"}
    rescue Serializer::FolderIntegrityError => e
      message = e.to_s
      if options[:delete_corrupt]
        serializer.delete
        message << " and has been deleted"
      end

      {
        name: serializer.folder,
        result: message
      }
    end
    {account: .username, folders: folder_results}
  end

  case options[:format]
  when "json"
    print_check_results_as_json(results)
  else
    print_check_results_as_text(results)
  end
end