Class: Pvectl::Presenters::AptPackage

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

Overview

Presenter for APT packages (pending updates and installed versions).

Standard columns highlight the upgrade path; wide columns add metadata useful when triaging updates.

Examples:

Using with formatter

presenter = AptPackage.new
formatter = Formatters::Table.new
output = formatter.format(packages, 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



21
22
23
# File 'lib/pvectl/presenters/apt_package.rb', line 21

def columns
  %w[NODE PACKAGE CURRENT AVAILABLE ORIGIN]
end

#extra_columnsArray<String>

Returns additional column headers for wide output.

Returns:

  • (Array<String>)

    extra column headers



28
29
30
# File 'lib/pvectl/presenters/apt_package.rb', line 28

def extra_columns
  %w[ARCH SECTION PRIORITY DESCRIPTION]
end

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

Returns additional values for wide output.

Parameters:

Returns:

  • (Array<String>)

    extra values matching extra_columns order



52
53
54
55
56
57
58
59
# File 'lib/pvectl/presenters/apt_package.rb', line 52

def extra_values(model, **_context)
  [
    model.arch || "-",
    model.section || "-",
    model.priority || "-",
    truncate(model.description, 60)
  ]
end

#to_hash(model) ⇒ Hash

Converts AptPackage model to hash for JSON/YAML output.

Parameters:

Returns:

  • (Hash)

    hash representation with string keys



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pvectl/presenters/apt_package.rb', line 65

def to_hash(model)
  {
    "node" => model.node,
    "package" => model.package,
    "title" => model.title,
    "current_version" => model.old_version,
    "available_version" => model.version,
    "origin" => model.origin,
    "arch" => model.arch,
    "section" => model.section,
    "priority" => model.priority,
    "description" => model.description,
    "notify_status" => model.notify_status,
    "current_state" => model.current_state,
    "manager_version" => model.manager_version,
    "running_kernel" => model.running_kernel
  }
end

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

Converts AptPackage model to table row values.

Parameters:

Returns:

  • (Array<String>)

    row values matching columns order



37
38
39
40
41
42
43
44
45
# File 'lib/pvectl/presenters/apt_package.rb', line 37

def to_row(model, **_context)
  [
    model.node || "-",
    model.package || "-",
    model.old_version || "-",
    model.version || "-",
    model.origin || "-"
  ]
end