Class: Pvectl::Presenters::Backup

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/presenters/backup.rb

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

Examples:

Using with formatter

presenter = Backup.new
formatter = Formatters::Table.new
output = formatter.format(backups, presenter)

See Also:

Instance Method Summary collapse

Methods inherited from Base

#tags_array, #tags_display, #template_display, #to_description, #to_wide_row, #uptime_human, #wide_columns

Instance Method Details

#columnsArray<String>

Returns column headers for standard table output.

Returns:

  • (Array<String>)

    column headers



23
24
25
# File 'lib/pvectl/presenters/backup.rb', line 23

def columns
  %w[VMID TYPE CREATED SIZE STORAGE PROTECTED]
end

#extra_columnsArray<String>

Returns additional column headers for wide output.

Returns:

  • (Array<String>)

    extra column headers



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.

Parameters:

  • model (Models::Backup)

    Backup model

  • context (Hash)

    optional context

Returns:

  • (Array)

    extra values matching extra_columns order



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

#to_hash(model) ⇒ Hash

Converts Backup model to hash for JSON/YAML output.

Parameters:

Returns:

  • (Hash)

    hash representation with string keys



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.

Parameters:

  • model (Models::Backup)

    Backup model

  • context (Hash)

    optional context

Returns:

  • (Array)

    row values matching columns order



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