Class: Pvectl::Presenters::Backup
- Defined in:
- lib/pvectl/presenters/backup.rb,
sig/pvectl/presenters/backup.rbs
Overview
Presenter for Backup models.
Formats backups for table, wide, JSON, and YAML output. Standard columns: VMID, TYPE, CREATED, SIZE, STORAGE, PROTECTED Wide columns add: FORMAT, NOTES, VOLID
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
Returns additional values for wide output.
-
#format_protected(protected_status) ⇒ String
Formats protected status for display.
-
#format_time(time) ⇒ String
Formats time for display.
-
#format_type(resource_type) ⇒ String
Formats resource type for display.
-
#to_hash(model) ⇒ Hash
Converts Backup model to hash for JSON/YAML output.
-
#to_row(model, **_context) ⇒ Array
Converts Backup model to table row values.
-
#truncate(text, max_length) ⇒ String?
Truncates text to specified length.
Methods inherited from Base
#format_bytes, #format_firewall, #format_firewall_rules, #format_task_history, #resource, #tags_array, #tags_display, #template_display, #to_description, #to_wide_row, #uptime_human, #wide_columns
Instance Method Details
#columns ⇒ Array<String>
Returns column headers for standard table output.
23 24 25 |
# File 'lib/pvectl/presenters/backup.rb', line 23 def columns %w[VMID TYPE CREATED SIZE STORAGE PROTECTED] end |
#extra_columns ⇒ Array<String>
Returns additional column headers for wide output.
30 31 32 |
# File 'lib/pvectl/presenters/backup.rb', line 30 def extra_columns %w[FORMAT NOTES VOLID] end |
#extra_values(model, **_context) ⇒ Array
Returns additional values for wide output.
55 56 57 58 59 60 61 |
# File 'lib/pvectl/presenters/backup.rb', line 55 def extra_values(model, **_context) [ model.format, truncate(model.notes, 30), model.volid ] end |
#format_protected(protected_status) ⇒ String
Formats protected status for display.
111 112 113 |
# File 'lib/pvectl/presenters/backup.rb', line 111 def format_protected(protected_status) protected_status ? "yes" : "no" end |
#format_time(time) ⇒ String
Formats time for display.
101 102 103 104 105 |
# File 'lib/pvectl/presenters/backup.rb', line 101 def format_time(time) return "-" if time.nil? time.strftime("%Y-%m-%d %H:%M:%S") end |
#format_type(resource_type) ⇒ String
Formats resource type for display.
89 90 91 92 93 94 95 |
# File 'lib/pvectl/presenters/backup.rb', line 89 def format_type(resource_type) case resource_type when :qemu then "qemu" when :lxc then "lxc" else "-" end end |
#to_hash(model) ⇒ Hash
Converts Backup model to hash for JSON/YAML output.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/pvectl/presenters/backup.rb', line 67 def to_hash(model) { "vmid" => model.vmid, "type" => format_type(model.resource_type), "volid" => model.volid, "storage" => model.storage, "node" => model.node, "size" => model.size, "size_human" => model.human_size, "created_at" => model.created_at&.iso8601, "format" => model.format, "notes" => model.notes, "protected" => model.protected? } end |
#to_row(model, **_context) ⇒ Array
Converts Backup model to table row values.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pvectl/presenters/backup.rb', line 39 def to_row(model, **_context) [ model.vmid, format_type(model.resource_type), format_time(model.created_at), model.human_size, model.storage, format_protected(model.protected?) ] end |
#truncate(text, max_length) ⇒ String?
Truncates text to specified length.
120 121 122 123 124 125 |
# File 'lib/pvectl/presenters/backup.rb', line 120 def truncate(text, max_length) return nil if text.nil? return text if text.length <= max_length "#{text[0, max_length - 3]}..." end |