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_tags ⇒ Object
- #current_template ⇒ Object
-
#initialize(proposed_stack, current_stack) ⇒ StackDiffer
constructor
A new instance of StackDiffer.
- #noecho_keys ⇒ Object
- #output_diff ⇒ Object
- #parameters_diff ⇒ Object
- #params_different? ⇒ Boolean
- #proposed_parameters ⇒ Object
- #proposed_tags ⇒ Object
- #proposed_template ⇒ Object
- #single_param_update?(param_name) ⇒ Boolean
- #tags_diff ⇒ Object
- #tags_different? ⇒ Boolean
Constructor Details
#initialize(proposed_stack, current_stack) ⇒ StackDiffer
Returns a new instance of StackDiffer.
6 7 8 9 |
# File 'lib/stack_master/stack_differ.rb', line 6 def initialize(proposed_stack, current_stack) @proposed_stack = proposed_stack @current_stack = current_stack end |
Instance Method Details
#body_diff ⇒ Object
47 48 49 50 51 52 |
# File 'lib/stack_master/stack_differ.rb', line 47 def body_diff @body_diff ||= Diff.new(name: 'Stack', before: current_template, after: proposed_template, context: 7) end |
#body_different? ⇒ Boolean
43 44 45 |
# File 'lib/stack_master/stack_differ.rb', line 43 def body_different? body_diff.different? end |
#current_parameters ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/stack_master/stack_differ.rb', line 24 def current_parameters if @current_stack YAML.dump(sort_params(@current_stack.parameters_with_defaults)) else '' end end |
#current_tags ⇒ Object
74 75 76 77 78 79 |
# File 'lib/stack_master/stack_differ.rb', line 74 def = @current_stack&. return '' if .nil? || .empty? YAML.dump(sort_params()) end |
#current_template ⇒ Object
17 18 19 20 21 22 |
# File 'lib/stack_master/stack_differ.rb', line 17 def current_template return '' unless @current_stack return @current_stack.template_body unless @current_stack.template_format == :json JSON.pretty_generate(TemplateUtils.template_hash(@current_stack.template_body)) + "\n" end |
#noecho_keys ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/stack_master/stack_differ.rb', line 97 def noecho_keys if @current_stack @current_stack.parameters_with_defaults.select do |key, value| value == '****' end.keys else [] end end |
#output_diff ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/stack_master/stack_differ.rb', line 88 def output_diff body_diff.display parameters_diff.display .display StackMaster.stdout.puts ' * can not tell if NoEcho parameters are different.' unless noecho_keys.empty? StackMaster.stdout.puts 'No stack found' if @current_stack.nil? end |
#parameters_diff ⇒ Object
58 59 60 61 62 |
# File 'lib/stack_master/stack_differ.rb', line 58 def parameters_diff @param_diff ||= Diff.new(name: 'Parameters', before: current_parameters, after: proposed_parameters) end |
#params_different? ⇒ Boolean
54 55 56 |
# File 'lib/stack_master/stack_differ.rb', line 54 def params_different? parameters_diff.different? end |
#proposed_parameters ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/stack_master/stack_differ.rb', line 32 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_tags ⇒ Object
81 82 83 84 85 86 |
# File 'lib/stack_master/stack_differ.rb', line 81 def = @proposed_stack. return '' if .nil? || .empty? YAML.dump(sort_params()) end |
#proposed_template ⇒ Object
11 12 13 14 15 |
# File 'lib/stack_master/stack_differ.rb', line 11 def proposed_template return @proposed_stack.template_body unless @proposed_stack.template_format == :json JSON.pretty_generate(JSON.parse(@proposed_stack.template_body)) + "\n" end |
#single_param_update?(param_name) ⇒ Boolean
107 108 109 110 111 112 113 114 115 |
# File 'lib/stack_master/stack_differ.rb', line 107 def single_param_update?(param_name) return false if param_name.blank? || @current_stack.blank? || body_different? differences = Hashdiff.diff(@current_stack.parameters_with_defaults, @proposed_stack.parameters_with_defaults) return false if differences.count != 1 diff = differences[0] diff[0] == '~' && diff[1] == param_name end |
#tags_diff ⇒ Object
68 69 70 71 72 |
# File 'lib/stack_master/stack_differ.rb', line 68 def @tags_diff ||= Diff.new(name: 'Tags', before: , after: ) end |
#tags_different? ⇒ Boolean
64 65 66 |
# File 'lib/stack_master/stack_differ.rb', line 64 def .different? end |