brew/Library/Homebrew/cask/lib/hbc/checkable.rb

52 lines
836 B
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
module Checkable
def errors
@errors ||= []
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def warnings
@warnings ||= []
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def add_error(message)
errors << message
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def add_warning(message)
warnings << message
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def errors?
errors.any?
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def warnings?
warnings.any?
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def result
if errors?
2016-08-30 21:38:13 +02:00
Formatter.error("failed")
2016-09-24 13:52:43 +02:00
elsif warnings?
2016-08-30 21:38:13 +02:00
Formatter.warning("warning")
2016-09-24 13:52:43 +02:00
else
2016-08-30 21:38:13 +02:00
Formatter.success("passed")
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
def summary
summary = ["#{summary_header}: #{result}"]
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
errors.each do |error|
2016-08-30 21:38:13 +02:00
summary << " #{Formatter.error("-")} #{error}"
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
warnings.each do |warning|
2016-08-30 21:38:13 +02:00
summary << " #{Formatter.warning("-")} #{warning}"
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
summary.join("\n")
end
2016-08-18 22:11:42 +03:00
end
end