Class: Patch::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/patch/report.rb

Overview

Terminal/Console output explaining the hub configuration

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hub) ⇒ Report

Returns a new instance of Report.

Parameters:

  • hub (Hub)

    The hub to report about



13
14
15
# File 'lib/patch/report.rb', line 13

def initialize(hub)
  @hub = hub
end

Class Method Details

Parameters:

  • hub (Hub)

    The hub to print a report for

Returns:



8
9
10
# File 'lib/patch/report.rb', line 8

def self.print(hub)
  new(hub).print
end

Instance Method Details

Print a report to standard out

Returns:



19
20
21
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
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/patch/report.rb', line 19

def print
  report = self.report
  puts
  
  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

#reportHash

Construct the report hash

Returns:

  • (Hash)


64
65
66
67
68
69
70
71
# 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