Sha256: 79f1e37cf857155c65ef4e2105bf0857b110965d510a06d57cfcfd0cdb29b695

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

class Lono::Inspector::Summary < Lono::Inspector::Base
  def perform
    puts "=> CloudFormation Template Summary:".colorize(:green)
    return if @options[:noop]

    print_parameters_summary

    puts "Resources:"
    print_resource_types
  end

  def print_parameters_summary
    if parameters.empty?
      puts "There are no parameters in this template."
    else
      print_parameters("Required Parameters", required_parameters)
      print_parameters("Optional Parameters", optional_parameters)
    end
  end

  def print_parameters(label, parameters)
    puts "#{label}:"
    if parameters.empty?
      puts "  There are no #{label.downcase} parameters"
    else
      parameters.each do |logical_id, p|
        output = "  #{logical_id} (#{p["Type"]})"
        if p["Default"]
          output << " Default: #{p["Default"]}"
        end
        puts output
      end
    end
  end

  def required_parameters
    parameters.reject { |logical_id, p| p["Default"] }
  end

  def optional_parameters
    parameters.select { |logical_id, p| p["Default"] }
  end

  def parameters
    data["Parameters"] || []
  end

  def resource_types
    types = Hash.new(0)
    data["Resources"].each do |logical_id, resource|
      types[resource["Type"]] += 1
    end
    types
  end

  def print_resource_types
    types = resource_types.sort_by {|r| r[1] * -1} # Hash -> 2D Array
    types.each do |a|
      type, count = a
      printf "%3s %s\n", count, type
    end
    printf "%3s %s\n", resource_types.size, "Total"
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lono-4.2.4 lib/lono/inspector/summary.rb
lono-4.2.3 lib/lono/inspector/summary.rb
lono-4.2.2 lib/lono/inspector/summary.rb
lono-4.2.1 lib/lono/inspector/summary.rb
lono-4.2.0 lib/lono/inspector/summary.rb
lono-4.1.0 lib/lono/inspector/summary.rb