Class: StackMaster::StackDiffer
- Inherits:
-
Object
- Object
- StackMaster::StackDiffer
- Defined in:
- lib/stack_master/stack_differ.rb
Instance Method Summary collapse
- #body_diff ⇒ Object
- #body_different? ⇒ Boolean
- #current_parameters ⇒ Object
- #current_template ⇒ Object
-
#initialize(proposed_stack, current_stack) ⇒ StackDiffer
constructor
A new instance of StackDiffer.
- #noecho_keys ⇒ Object
- #output_diff ⇒ Object
- #params_diff ⇒ Object
- #params_different? ⇒ Boolean
- #proposed_parameters ⇒ Object
- #proposed_template ⇒ Object
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_diff ⇒ Object
43 44 45 |
# File 'lib/stack_master/stack_differ.rb', line 43 def body_diff @body_diff ||= Diffy::Diff.new(current_template, proposed_template, context: 7, include_diff_info: true).to_s end |
#body_different? ⇒ Boolean
39 40 41 |
# File 'lib/stack_master/stack_differ.rb', line 39 def body_different? body_diff != '' end |
#current_parameters ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/stack_master/stack_differ.rb', line 20 def current_parameters if @current_stack YAML.dump(sort_params(@current_stack.parameters_with_defaults)) else '' end end |
#current_template ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/stack_master/stack_differ.rb', line 12 def current_template if @current_stack JSON.pretty_generate(@current_stack.template_hash) else '' end end |
#noecho_keys ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/stack_master/stack_differ.rb', line 64 def noecho_keys if @current_stack @current_stack.parameters_with_defaults.select do |key, value| value == "****" end.keys else [] end end |
#output_diff ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/stack_master/stack_differ.rb', line 55 def output_diff display_diff('Stack', body_diff) display_diff('Parameters', params_diff) unless noecho_keys.empty? StackMaster.stdout.puts " * can not tell if NoEcho parameters are different." end StackMaster.stdout.puts "No stack found" if @current_stack.nil? end |
#params_diff ⇒ Object
51 52 53 |
# File 'lib/stack_master/stack_differ.rb', line 51 def params_diff @param_diff ||= Diffy::Diff.new(current_parameters, proposed_parameters, {}).to_s end |
#params_different? ⇒ Boolean
47 48 49 |
# File 'lib/stack_master/stack_differ.rb', line 47 def params_different? params_diff != '' end |
#proposed_parameters ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/stack_master/stack_differ.rb', line 28 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_template ⇒ Object
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 |