Class: Pvectl::Presenters::HostsFile

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

Overview

Presenter for per-node /etc/hosts content.

/etc/hosts is raw text — pvectl does not attempt to parse it. In table mode only summary metadata is shown (node, line count, digest). JSON/YAML output exposes the raw ‘data` string. Describe output prints the full content under a “Content” key.

See Also:

Instance Method Summary collapse

Methods inherited from Base

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

Instance Method Details

#columnsArray<String>

Returns column headers for standard table output.

Returns:

  • (Array<String>)

    column headers



18
19
20
# File 'lib/pvectl/presenters/hosts_file.rb', line 18

def columns
  %w[NODE LINES DIGEST]
end

#to_description(model) ⇒ Hash

Converts HostsFile model to describe format (kubectl-style).

Parameters:

Returns:

  • (Hash)

    structured hash for describe formatter



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

def to_description(model)
  {
    "Node" => model.node || "-",
    "Digest" => model.digest || "-",
    "Lines" => model.line_count.to_s,
    "Content" => model.data.empty? ? "(empty)" : model.data
  }
end

#to_hash(model) ⇒ Hash

Converts HostsFile model to hash for JSON/YAML output.

Parameters:

Returns:

  • (Hash)

    hash representation with string keys



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

def to_hash(model)
  {
    "node" => model.node,
    "data" => model.data,
    "digest" => model.digest
  }
end

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

Converts HostsFile model to table row values.

Parameters:

  • model (Models::HostsFile)

    HostsFile model

  • _context (Hash)

    optional context (unused)

Returns:

  • (Array<String>)

    row values matching columns order



27
28
29
30
31
32
33
# File 'lib/pvectl/presenters/hosts_file.rb', line 27

def to_row(model, **_context)
  [
    model.node || "-",
    model.line_count.to_s,
    model.digest || "-"
  ]
end