Class: Pangea::CLI::TofuEvents::Collector
- Defined in:
- lib/pangea/cli/tofu_events.rb
Overview
Accumulates events and exposes summary information.
Instance Attribute Summary collapse
-
#apply_summary ⇒ Object
readonly
Returns the value of attribute apply_summary.
-
#dropped_warnings ⇒ Object
readonly
Returns the value of attribute dropped_warnings.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#plan_summary ⇒ Object
readonly
Returns the value of attribute plan_summary.
-
#transient_errors ⇒ Object
readonly
Returns the value of attribute transient_errors.
Instance Method Summary collapse
- #any_transient_errors? ⇒ Boolean
- #consume(event) ⇒ Object
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
-
#summary_line ⇒ Object
Nord-themed one-line summary.
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
95 96 97 98 99 100 101 |
# File 'lib/pangea/cli/tofu_events.rb', line 95 def initialize @events = [] @transient_errors = [] @dropped_warnings = [] @plan_summary = nil @apply_summary = nil end |
Instance Attribute Details
#apply_summary ⇒ Object (readonly)
Returns the value of attribute apply_summary.
91 92 93 |
# File 'lib/pangea/cli/tofu_events.rb', line 91 def apply_summary @apply_summary end |
#dropped_warnings ⇒ Object (readonly)
Returns the value of attribute dropped_warnings.
91 92 93 |
# File 'lib/pangea/cli/tofu_events.rb', line 91 def dropped_warnings @dropped_warnings end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
91 92 93 |
# File 'lib/pangea/cli/tofu_events.rb', line 91 def events @events end |
#plan_summary ⇒ Object (readonly)
Returns the value of attribute plan_summary.
91 92 93 |
# File 'lib/pangea/cli/tofu_events.rb', line 91 def plan_summary @plan_summary end |
#transient_errors ⇒ Object (readonly)
Returns the value of attribute transient_errors.
91 92 93 |
# File 'lib/pangea/cli/tofu_events.rb', line 91 def transient_errors @transient_errors end |
Instance Method Details
#any_transient_errors? ⇒ Boolean
121 |
# File 'lib/pangea/cli/tofu_events.rb', line 121 def any_transient_errors? = !@transient_errors.empty? |
#consume(event) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/pangea/cli/tofu_events.rb', line 103 def consume(event) @events << event @transient_errors << event if event.transient_error? @dropped_warnings << event if event.dropped_warning? if event.type == 'change_summary' changes = event.changes || {} # OpenTofu emits `operation` inside the `changes` hash, not at # event root. Fall back to top-level for forward compat. op = changes['operation'] || event.operation if op == 'plan' @plan_summary = changes elsif op == 'apply' @apply_summary = changes end end end |
#summary_line ⇒ Object
Nord-themed one-line summary. Zero counts are muted, non-zero counts use semantic colors (create=green, change=cyan, destroy=red).
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/pangea/cli/tofu_events.rb', line 125 def summary_line t = Theme if @apply_summary a, c, r = @apply_summary.values_at('add', 'change', 'remove').map(&:to_i) "#{t.bold(t.color(:heading, 'Apply:'))} " \ "#{t.color(:create, a)} added, " \ "#{t.color(:update, c)} changed, " \ "#{t.color(:delete, r)} destroyed" elsif @plan_summary a, c, r = @plan_summary.values_at('add', 'change', 'remove').map(&:to_i) if (a + c + r).zero? t.bold(t.color(:heading, 'Plan: No changes.')) else "#{t.bold(t.color(:heading, 'Plan:'))} " \ "#{t.color(:create, a)} to add, " \ "#{t.color(:update, c)} to change, " \ "#{t.color(:delete, r)} to destroy" end end end |