Class: Pvectl::Selectors::Disk
- Defined in:
- lib/pvectl/selectors/disk.rb,
sig/pvectl/selectors/disk.rbs
Overview
Selector for filtering physical disks.
Extends Base with disk-specific field extraction. Supports: type, health, used, node, gpt, mounted.
Constant Summary collapse
- SUPPORTED_FIELDS =
%w[type health used node gpt mounted].freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#apply(disks) ⇒ Array<Models::PhysicalDisk>
Applies selector to disk collection.
-
#extract_value(disk, field) ⇒ String?
Extracts field value from PhysicalDisk model.
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(disks) ⇒ Array<Models::PhysicalDisk>
Applies selector to disk collection.
25 26 27 28 29 |
# File 'lib/pvectl/selectors/disk.rb', line 25 def apply(disks) return disks if empty? disks.select { |disk| matches?(disk) } end |
#extract_value(disk, field) ⇒ String?
Extracts field value from PhysicalDisk model.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pvectl/selectors/disk.rb', line 39 def extract_value(disk, field) case field when "type" disk.type when "health" disk.health when "used" disk.used when "node" disk.node when "gpt" disk.gpt? ? "yes" : "no" when "mounted" disk.mounted? ? "yes" : "no" else raise ArgumentError, "Unknown field: #{field}. Supported: #{SUPPORTED_FIELDS.join(', ')}" end end |