Class: Pvectl::Presenters::Template

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

Overview

Presenter for template listing (mixed VM and Container templates).

Handles both Models::Vm and Models::Container via duck typing. Both models share: vmid, name, type, node, maxdisk, tags.

Examples:

Using with formatter

presenter = Template.new
formatter = Formatters::Table.new
output = formatter.format(templates, presenter)

See Also:

Instance Method Summary collapse

Methods inherited from Base

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

Instance Method Details

#columnsArray<String>

Returns column headers for template listing.

Returns:

  • (Array<String>)

    column names



22
23
24
# File 'lib/pvectl/presenters/template.rb', line 22

def columns
  %w[ID NAME TYPE NODE DISK TAGS]
end

#to_hash(model) ⇒ Hash

Converts a template model to hash for JSON/YAML.

Parameters:

Returns:

  • (Hash)

    hash representation



46
47
48
49
50
51
52
53
54
55
# File 'lib/pvectl/presenters/template.rb', line 46

def to_hash(model)
  {
    "id" => model.vmid,
    "name" => model.name,
    "type" => model.type,
    "node" => model.node,
    "disk" => model.maxdisk,
    "tags" => model.tags
  }
end

#to_row(model, **_context) ⇒ Array<String>

Converts a template model to table row.

Parameters:

Returns:

  • (Array<String>)

    row values



31
32
33
34
35
36
37
38
39
40
# File 'lib/pvectl/presenters/template.rb', line 31

def to_row(model, **_context)
  [
    model.vmid.to_s,
    model.name || "-",
    model.type || "-",
    model.node || "-",
    format_disk(model.maxdisk),
    model.tags || "-"
  ]
end