class Patch::Report
Terminal/Console output explaining the hub configuration
Public Class Methods
new(hub)
click to toggle source
@param [Hub] hub The hub to report about
# File lib/patch/report.rb, line 13 def initialize(hub) @hub = hub end
print(hub)
click to toggle source
@param [Hub] hub The hub to print a report for @return [Report]
# File lib/patch/report.rb, line 8 def self.print(hub) new(hub).print end
Public Instance Methods
print()
click to toggle source
Print a report to standard out @return [Report] self
# File lib/patch/report.rb, line 19 def print report = self.report puts print_logo puts puts Rainbow("IPs").cyan puts Rainbow("———").cyan report[:ips].each { |ip| puts ip } puts puts Rainbow("Nodes").cyan puts Rainbow("———").cyan report[:nodes].each do |node| puts "#{node[:id]}: #{node[:name]}" end puts if report[:patches].count > 0 puts Rainbow("Patches").cyan puts Rainbow("———").cyan report[:patches].each_with_index do |patch, i| puts "#{i+1}. #{patch[:name]}" puts Rainbow("|").cyan puts Rainbow("| Node Map").cyan puts Rainbow("| ———").cyan patch[:maps].each { |map| puts Rainbow("| ").cyan + map } puts Rainbow("|").cyan puts Rainbow("| Actions").cyan puts Rainbow("| ———").cyan chunked_actions(patch[:actions]).each do |chunk| puts Rainbow("| ").cyan + chunk end puts Rainbow("|").cyan puts end else puts end unless report[:log].nil? puts "Logging to #{report[:log]}" puts end self end
report()
click to toggle source
Construct the report hash @return [Hash]
# File lib/patch/report.rb, line 64 def report report = {} report[:ips] = @hub.ips report[:nodes] = @hub.nodes.sort_by(&:id).map { |node| node_report(node) } report[:patches] = @hub.patches.map { |patch| patch_report(patch) } report[:log] = @hub.log.path unless @hub.log.nil? report end
Private Instance Methods
chunked_actions(actions)
click to toggle source
Get a patch action formatted for terminal width @param [Array<String>] actions @return [Array<String>]
# File lib/patch/report.rb, line 78 def chunked_actions(actions) max_length = columns - 10 chunks = [] actions.each do |action| if chunks.last.nil? || chunks.last.length >= max_length - action.length chunks << "" end chunk = chunks.last chunk << "#{action}" chunk << ", " unless action == actions.last end chunks end
columns()
click to toggle source
The number of columns of the terminal @return [Fixnum]
# File lib/patch/report.rb, line 94 def columns `tput cols`.to_i rescue 80 end
node_report(node)
click to toggle source
Construct the report about a node @return [Hash]
# File lib/patch/report.rb, line 114 def node_report(node) report = {} report[:id] = node.id report[:name] = node.class.name report end
patch_report(patch)
click to toggle source
Construct the report about a patch @return [Hash]
# File lib/patch/report.rb, line 123 def patch_report(patch) report = {} report[:name] = patch.name report[:maps] = patch.maps.map { |map| "#{map.from.map(&:id)} => #{map.to.map(&:id)}" } report[:actions] = patch.actions.map { |mapping| mapping[:name] } report end
print_logo()
click to toggle source
Output the patch logo @return [Boolean]
# File lib/patch/report.rb, line 100 def print_logo color = :blue puts Rainbow("██████╗ █████╗ ████████╗ ██████╗██╗ ██╗").send(color) puts Rainbow("██╔══██╗██╔══██╗╚══██╔══╝██╔════╝██║ ██║").send(color) puts Rainbow("██████╔╝███████║ ██║ ██║ ███████║").send(color) puts Rainbow("██╔═══╝ ██╔══██║ ██║ ██║ ██╔══██║").send(color) puts Rainbow("██║ ██║ ██║ ██║ ╚██████╗██║ ██║").send(color) puts Rainbow("╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╣").send(color) puts Rainbow("═≡≡≡▓▓▓═════════════════════════════════╝").send(color) true end