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]

Public Instance Methods

print() click to toggle source

Print a report to standard out @return [Report] self

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