class AwsCftTools::Runbooks::Diff::Context

The context of stacks and templates for a Diff report.

Constants

DIFF_OPTIONS

The options provided to the diff command to build template diffs.

Attributes

options[R]
stacks[R]
templates[R]

Public Class Methods

new(stacks, templates, options = {}) click to toggle source

@param stacks [Array<AwsCftTools::Stack>] @param templates [AwsCftTools::TemplateSet] @param options [Hash]

# File lib/aws_cft_tools/runbooks/diff/context.rb, line 29
def initialize(stacks, templates, options = {})
  @stacks = build_map(stacks)
  @templates = build_map(templates)
  @options = options
end

Public Instance Methods

report_on_differences() click to toggle source

Reports on the differences in the template bodies between the set of templates and the deployed stacks.

# File lib/aws_cft_tools/runbooks/diff/context.rb, line 53
def report_on_differences
  # these are stacks with templates
  output_report_on_differences(build_diffs)
end
report_on_missing_stacks() click to toggle source

Reports out templates that do not have corresponding stacks.

# File lib/aws_cft_tools/runbooks/diff/context.rb, line 45
def report_on_missing_stacks
  output_report_on_missing_stacks(templates.keys - stacks.keys)
end
report_on_missing_templates() click to toggle source

Reports out stacks that do not have corresponding templates.

# File lib/aws_cft_tools/runbooks/diff/context.rb, line 38
def report_on_missing_templates
  output_report_on_missing_templates(stacks.keys - templates.keys)
end

Private Instance Methods

build_diff(stack, template) click to toggle source
# File lib/aws_cft_tools/runbooks/diff/context.rb, line 76
def build_diff(stack, template)
  output_type = options[:colorize] ? :color : :text
  Diffy::Diff.new(
    stack.template_source, template.template_source_for_aws,
    include_diff_info: true, diff: DIFF_OPTIONS
  ).to_s(output_type)
end
build_diffs() click to toggle source
# File lib/aws_cft_tools/runbooks/diff/context.rb, line 66
def build_diffs
  stacks
    .keys
    .sort
    .select { |fn| templates[fn] }
    .each_with_object({}) do |name, acc|
      acc[name] = build_diff(stacks[name], templates[name])
    end
end
build_map(list) click to toggle source
# File lib/aws_cft_tools/runbooks/diff/context.rb, line 60
def build_map(list)
  list.each_with_object({}) do |thing, map|
    map[thing.name] = thing
  end
end