Class: Imap::Backup::CLI::Local::Check
- Inherits:
-
Object
- Object
- Imap::Backup::CLI::Local::Check
show all
- Includes:
- Helpers
- Defined in:
- lib/imap/backup/cli/local/check.rb
Instance Attribute Summary collapse
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.
18
19
20
|
# File 'lib/imap/backup/cli/local/check.rb', line 18
def initialize(options)
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
16
17
18
|
# File 'lib/imap/backup/cli/local/check.rb', line 16
def options
@options
end
|
Instance Method Details
#config ⇒ Object
64
65
66
|
# File 'lib/imap/backup/cli/local/check.rb', line 64
def config
@config ||= load_config(**options)
end
|
#print_check_results_as_json(results) ⇒ Object
51
52
53
|
# File 'lib/imap/backup/cli/local/check.rb', line 51
def print_check_results_as_json(results)
Kernel.puts results.to_json
end
|
#print_check_results_as_text(results) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/imap/backup/cli/local/check.rb', line 55
def print_check_results_as_text(results)
results.each do |account_results|
Kernel.puts "Account: #{account_results[:account]}"
account_results[:folders].each do |folder_results|
Kernel.puts "\t#{folder_results[:name]}: #{folder_results[:result]}"
end
end
end
|
#run ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/imap/backup/cli/local/check.rb', line 22
def run
results = requested_accounts(config).map do |account|
serialized_folders = Account::SerializedFolders.new(account: 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: 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
|