Class: Hackmac::ContainerDisk

Inherits:
Disks
  • Object
show all
Defined in:
lib/hackmac/disks.rb

Overview

A class that provides access to APFS container disk information by querying macOS’s diskutil command

The ContainerDisk class extends the Disks class to specifically retrieve and process information about Apple File System (APFS) containers

This class initializes by taking a disk identifier and searching for the corresponding Apple_APFS device within the diskutil list output

It then uses the APFS device path to construct a Disks instance, allowing access to detailed APFS container information through dynamic method calls

Examples:

container_disk = Hackmac::ContainerDisk.new(disk: '/dev/disk0')
# Provides access to APFS container information through method calls

Instance Method Summary collapse

Methods included from Plist

#as_hash, #each, #method_missing, #plist, #to_json

Constructor Details

#initialize(disk:, limiter: nil) ⇒ ContainerDisk

The initialize method sets up a ContainerDisk instance by identifying and initializing with the APFS device associated with a given disk.

This method takes a disk identifier and searches for the corresponding Apple_APFS device within the diskutil list output. It extracts the device path and passes it along to the parent Disks class constructor, allowing for further processing of APFS container information.

Parameters:

  • disk (String)

    the disk identifier to search for APFS container device

  • limiter (String) (defaults to: nil)

    optional parameter to limit the output of diskutil list



93
94
95
96
97
98
99
# File 'lib/hackmac/disks.rb', line 93

def initialize(disk:, limiter: nil)
  @disk = disk
  device = `#{Shellwords.join(%w[ diskutil list ] << disk)}`.
    lines.grep(/Apple_APFS/).first&.split(/\s+/)&.[](4)

  super device: device, limiter: limiter
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hackmac::Plist