Class: Lono::Inspector::Summary

Inherits:
Base
  • Object
show all
Defined in:
lib/lono/inspector/summary.rb

Instance Method Summary collapse

Methods inherited from Base

#check_template_exists, #data, #generate_templates, #initialize, #run

Constructor Details

This class inherits a constructor from Lono::Inspector::Base

Instance Method Details

#optional_parametersObject



40
41
42
# File 'lib/lono/inspector/summary.rb', line 40

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

#parametersObject



44
45
46
# File 'lib/lono/inspector/summary.rb', line 44

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

#performObject



2
3
4
5
6
7
8
9
10
# File 'lib/lono/inspector/summary.rb', line 2

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

  print_parameters_summary

  puts "Resources:"
  print_resource_types
end


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lono/inspector/summary.rb', line 21

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


12
13
14
15
16
17
18
19
# File 'lib/lono/inspector/summary.rb', line 12

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


56
57
58
59
60
61
62
63
# File 'lib/lono/inspector/summary.rb', line 56

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

#required_parametersObject



36
37
38
# File 'lib/lono/inspector/summary.rb', line 36

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

#resource_typesObject



48
49
50
51
52
53
54
# File 'lib/lono/inspector/summary.rb', line 48

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