Class: Pvectl::Presenters::Snapshot
- Defined in:
- lib/pvectl/presenters/snapshot.rb
Overview
Presenter for VM/container snapshots.
Defines column layout and formatting for snapshot table output. Supports both list (get) and describe output modes.
Standard columns: VMID, NAME, CREATED, DESCRIPTION Wide columns add: TYPE, VMSTATE, PARENT
Instance Method Summary collapse
-
#columns ⇒ Array<String>
Returns column headers for standard table output.
-
#extra_columns ⇒ Array<String>
Returns additional column headers for wide output.
-
#extra_values(model, **_context) ⇒ Array<String>
Returns additional values for wide output.
-
#to_description(model) ⇒ Hash
Returns describe output for SnapshotDescription or plain Snapshot.
-
#to_hash(model) ⇒ Hash+
Converts model to hash for JSON/YAML output.
-
#to_row(model, **_context) ⇒ Array<String>
Converts Snapshot model to table row values.
Methods inherited from Base
#tags_array, #tags_display, #template_display, #to_wide_row, #uptime_human, #wide_columns
Instance Method Details
#columns ⇒ Array<String>
Returns column headers for standard table output.
26 27 28 |
# File 'lib/pvectl/presenters/snapshot.rb', line 26 def columns %w[VMID NAME CREATED DESCRIPTION] end |
#extra_columns ⇒ Array<String>
Returns additional column headers for wide output.
33 34 35 |
# File 'lib/pvectl/presenters/snapshot.rb', line 33 def extra_columns %w[TYPE VMSTATE PARENT] end |
#extra_values(model, **_context) ⇒ Array<String>
Returns additional values for wide output.
56 57 58 59 60 61 62 |
# File 'lib/pvectl/presenters/snapshot.rb', line 56 def extra_values(model, **_context) [ model.resource_type&.to_s || "-", model.has_vmstate? ? "yes" : "no", model.parent || "-" ] end |
#to_description(model) ⇒ Hash
Returns describe output for SnapshotDescription or plain Snapshot.
92 93 94 95 96 97 98 99 100 |
# File 'lib/pvectl/presenters/snapshot.rb', line 92 def to_description(model) return snapshot_to_hash(model) unless model.is_a?(Models::SnapshotDescription) if model.single? build_single_description(model.entries.first) else build_multi_description(model.entries) end end |
#to_hash(model) ⇒ Hash+
Converts model to hash for JSON/YAML output.
Handles both Models::Snapshot (for list) and Models::SnapshotDescription (for describe).
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pvectl/presenters/snapshot.rb', line 71 def to_hash(model) return snapshot_to_hash(model) unless model.is_a?(Models::SnapshotDescription) if model.single? entry = model.entries.first snapshot_to_hash(entry.snapshot).merge( "snapshot_tree" => build_tree_data(entry) ) else model.entries.map do |entry| snapshot_to_hash(entry.snapshot).merge( "snapshot_tree" => build_tree_data(entry) ) end end end |
#to_row(model, **_context) ⇒ Array<String>
Converts Snapshot model to table row values.
42 43 44 45 46 47 48 49 |
# File 'lib/pvectl/presenters/snapshot.rb', line 42 def to_row(model, **_context) [ model.vmid.to_s, model.name, format_time(model.created_at), model.description || "-" ] end |