Class: Pvectl::Selectors::Volume

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/selectors/volume.rb,
sig/pvectl/selectors/volume.rbs

Overview

Selector for filtering virtual disk volumes.

Extends Base with volume-specific field extraction. Supports: format, storage, node, content, resource_type, name.

Examples:

Filter raw volumes only

selector = Volume.parse("format=raw")
raw_vols = selector.apply(all_volumes)

Filter volumes on a specific storage and node

selector = Volume.parse("storage=local-lvm,node=pve1")
filtered = selector.apply(all_volumes)

Constant Summary collapse

SUPPORTED_FIELDS =
%w[format storage node content resource_type name].freeze

Instance Attribute Summary

Attributes inherited from Base

#conditions

Instance Method Summary collapse

Methods inherited from Base

#compare_value, #empty?, #initialize, #match_condition?, #matches?, parse, parse_all, #wildcard_match?

Constructor Details

This class inherits a constructor from Pvectl::Selectors::Base

Instance Method Details

#apply(volumes) ⇒ Array<Models::Volume>

Applies selector to volume collection.



25
26
27
28
29
# File 'lib/pvectl/selectors/volume.rb', line 25

def apply(volumes)
  return volumes if empty?

  volumes.select { |vol| matches?(vol) }
end

#extract_value(vol, field) ⇒ String?

Extracts field value from Volume model.

Raises:

  • (ArgumentError)

    if field is not supported



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pvectl/selectors/volume.rb', line 39

def extract_value(vol, field)
  case field
  when "format"
    vol.format
  when "storage"
    vol.storage
  when "node"
    vol.node
  when "content"
    vol.content
  when "resource_type"
    vol.resource_type
  when "name"
    vol.name
  else
    raise ArgumentError, "Unknown field: #{field}. Supported: #{SUPPORTED_FIELDS.join(', ')}"
  end
end