Class: Pvectl::Commands::Top::Handlers::Vms

Inherits:
Object
  • Object
show all
Includes:
ResourceHandler
Defined in:
lib/pvectl/commands/top/handlers/vms.rb,
sig/pvectl/commands/top/handlers/vms.rbs

Overview

Handler for Top command VM metrics display.

Wraps Get::Handlers::Vms to fetch VM data and pairs it with TopVm presenter for metrics-focused output.

Examples:

Using via ResourceRegistry

handler = Top::ResourceRegistry.for("vms")
vms = handler.list(sort: "cpu")
presenter = handler.presenter

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(get_handler: nil) ⇒ Vms

Creates handler with optional Get handler for dependency injection.

Parameters:

  • (defaults to: nil)

    handler (default: create new)

  • (defaults to: nil)


26
27
28
# File 'lib/pvectl/commands/top/handlers/vms.rb', line 26

def initialize(get_handler: nil)
  @get_handler = get_handler
end

Instance Method Details

#get_handlerGet::Handlers::Vms

Returns Get handler, creating it if necessary.

Returns:

  • Vms get handler



50
51
52
# File 'lib/pvectl/commands/top/handlers/vms.rb', line 50

def get_handler
  @get_handler ||= Get::Handlers::Vms.new
end

#list(sort: nil, **_) ⇒ Array<Models::Vm>

Lists VMs with optional sorting.

Parameters:

  • (defaults to: nil)

    sort field (cpu, memory, disk)

  • (defaults to: nil)

Returns:

  • collection of VM models



34
35
36
# File 'lib/pvectl/commands/top/handlers/vms.rb', line 34

def list(sort: nil, **_)
  get_handler.list(sort: sort)
end

#presenterPresenters::TopVm

Returns Top-specific presenter for VMs.

Returns:

  • TopVm presenter instance



41
42
43
# File 'lib/pvectl/commands/top/handlers/vms.rb', line 41

def presenter
  Presenters::TopVm.new
end