Class: StackMaster::StackDiffer

Inherits:
Object
  • Object
show all
Defined in:
lib/stack_master/stack_differ.rb

Instance Method Summary collapse

Constructor Details

#initialize(proposed_stack, current_stack) ⇒ StackDiffer

Returns a new instance of StackDiffer.



3
4
5
6
# File 'lib/stack_master/stack_differ.rb', line 3

def initialize(proposed_stack, current_stack)
  @proposed_stack = proposed_stack
  @current_stack = current_stack
end

Instance Method Details

#body_different?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/stack_master/stack_differ.rb', line 31

def body_different?
  Diffy::Diff.new(current_template, proposed_template, {}).to_s != ''
end

#current_parametersObject



16
17
18
# File 'lib/stack_master/stack_differ.rb', line 16

def current_parameters
  YAML.dump(sort_params(@current_stack.parameters_with_defaults))
end

#current_templateObject



12
13
14
# File 'lib/stack_master/stack_differ.rb', line 12

def current_template
  JSON.pretty_generate(@current_stack.template_hash)
end

#noecho_keysObject



53
54
55
56
57
58
59
60
61
# File 'lib/stack_master/stack_differ.rb', line 53

def noecho_keys
  if @current_stack
    @current_stack.parameters_with_defaults.select do |key, value|
      value == "****"
    end.keys
  else
    []
  end
end

#output_diffObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/stack_master/stack_differ.rb', line 39

def output_diff
  if @current_stack
    text_diff('Stack', current_template, proposed_template, context: 7, include_diff_info: true)
    text_diff('Parameters', current_parameters, proposed_parameters)
    unless noecho_keys.empty?
      StackMaster.stdout.puts " * can not tell if NoEcho parameters are different."
    end
  else
    text_diff('Stack', '', proposed_template)
    text_diff('Parameters', '', proposed_parameters)
    StackMaster.stdout.puts "No stack found"
  end
end

#params_different?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/stack_master/stack_differ.rb', line 35

def params_different?
  Diffy::Diff.new(current_parameters, proposed_parameters, {}).to_s != ''
end

#proposed_parametersObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/stack_master/stack_differ.rb', line 20

def proposed_parameters
  # **** out any secret parameters in the current stack.
  params = @proposed_stack.parameters_with_defaults
  if @current_stack
    noecho_keys.each do |key|
      params[key] = "****"
    end
  end
  YAML.dump(sort_params(params))
end

#proposed_templateObject



8
9
10
# File 'lib/stack_master/stack_differ.rb', line 8

def proposed_template
  JSON.pretty_generate(JSON.parse(@proposed_stack.template_body))
end