Class: Pvectl::Presenters::DnsConfig

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

Overview

Presenter for per-node DNS resolver configuration.

Defines column layout for table output and structured data for JSON/YAML and describe output. DNS is a singleton resource per node.

Examples:

Using with formatter

presenter = DnsConfig.new
formatter = Formatters::Table.new
output = formatter.format([dns_model], presenter)

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



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

def columns
  %w[NODE SEARCH DNS1 DNS2 DNS3]
end

#to_description(model) ⇒ Hash

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

Parameters:

Returns:

  • (Hash)

    structured hash for describe formatter



58
59
60
61
62
63
64
65
# File 'lib/pvectl/presenters/dns_config.rb', line 58

def to_description(model)
  servers = model.servers
  {
    "Node" => model.node || "-",
    "Search Domain" => model.search || "-",
    "Nameservers" => servers.empty? ? "-" : servers
  }
end

#to_hash(model) ⇒ Hash

Converts DnsConfig model to hash for JSON/YAML output.

Parameters:

Returns:

  • (Hash)

    hash representation with string keys



44
45
46
47
48
49
50
51
52
# File 'lib/pvectl/presenters/dns_config.rb', line 44

def to_hash(model)
  {
    "node" => model.node,
    "search" => model.search,
    "dns1" => model.dns1,
    "dns2" => model.dns2,
    "dns3" => model.dns3
  }
end

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

Converts DnsConfig model to table row values.

Parameters:

  • model (Models::DnsConfig)

    DNS configuration model

  • _context (Hash)

    optional context (unused)

Returns:

  • (Array<String>)

    row values matching columns order



30
31
32
33
34
35
36
37
38
# File 'lib/pvectl/presenters/dns_config.rb', line 30

def to_row(model, **_context)
  [
    model.node || "-",
    model.search || "-",
    model.dns1 || "-",
    model.dns2 || "-",
    model.dns3 || "-"
  ]
end