Class: Pvectl::Presenters::Config::Context

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

Overview

Presenter for formatting context list output.

Context presenter provides column definitions and row formatting for displaying contexts in table, wide table, JSON, and YAML formats. Inherits from Base to support unified output formatting.

Examples:

Using with OutputHelper

presenter = Context.new
OutputHelper.print(
  data: contexts,
  presenter: presenter,
  format: "table",
  current_context: "production"
)

Wide format includes DEFAULT-NODE column

pvectl config get-contexts -o wide
# CURRENT  NAME        CLUSTER  USER       DEFAULT-NODE
# *        production  prod     admin@pam  pve1

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 the column headers for table output.

Returns:

  • (Array<String>)

    column names



30
31
32
# File 'lib/pvectl/presenters/config/context.rb', line 30

def columns
  ["CURRENT", "NAME", "CLUSTER", "USER"]
end

#extra_columnsArray<String>

Returns additional columns for wide format.

Returns:

  • (Array<String>)

    extra column names



37
38
39
# File 'lib/pvectl/presenters/config/context.rb', line 37

def extra_columns
  ["DEFAULT-NODE"]
end

#extra_values(context, **context_kwargs) ⇒ Array<String, nil>

Returns additional values for wide format.

Parameters:

Returns:

  • (Array<String, nil>)

    extra values



61
62
63
# File 'lib/pvectl/presenters/config/context.rb', line 61

def extra_values(context, **context_kwargs)
  [context.default_node]
end

#to_hash(context) ⇒ Hash

Converts a context to a hash for JSON/YAML output.

Parameters:

Returns:

  • (Hash)

    hash representation



69
70
71
72
73
74
75
76
# File 'lib/pvectl/presenters/config/context.rb', line 69

def to_hash(context)
  {
    "name" => context.name,
    "cluster" => context.cluster_ref,
    "user" => context.user_ref,
    "default_node" => context.default_node
  }
end

#to_row(context, current_context: nil, **context_kwargs) ⇒ Array<String>

Converts a context to a table row.

Parameters:

  • context (Config::Models::Context)

    context to format

  • current_context (String, nil) (defaults to: nil)

    name of the current context

  • context_kwargs (Hash)

    additional context (ignored)

Returns:

  • (Array<String>)

    row values



47
48
49
50
51
52
53
54
# File 'lib/pvectl/presenters/config/context.rb', line 47

def to_row(context, current_context: nil, **context_kwargs)
  [
    context.name == current_context ? "*" : "",
    context.name,
    context.cluster_ref,
    context.user_ref
  ]
end