Class: Hackmac::DiskInfo

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

Overview

A class that provides detailed information about a specific disk by querying the system’s disk utility.

The DiskInfo class interfaces with macOS’s diskutil command to retrieve comprehensive details about a specified disk.

Examples:

disk_info = Hackmac::DiskInfo.new(disk: '/dev/disk0')
# Provides access to disk information through method calls

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Plist

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

Constructor Details

#initialize(disk:) ⇒ DiskInfo

The initialize method sets up a DiskInfo instance by retrieving detailed information about a specific disk.

This method constructs and executes a system command to fetch comprehensive details about the specified disk using diskutil’s info functionality with plist output format. The resulting plist data is parsed and made available for querying through dynamic method calls.

Parameters:

  • disk (String)

    the disk identifier to retrieve information for



24
25
26
27
# File 'lib/hackmac/disks.rb', line 24

def initialize(disk:)
  @disk = disk
  plist(**(%w[ diskutil info -plist ] << disk))
end

Dynamic Method Handling

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

Instance Attribute Details

#diskString (readonly)

The disk reader method provides access to the disk identifier that was used when initializing the DiskInfo instance.

Returns:

  • (String)

    the disk identifier associated with this instance



33
34
35
# File 'lib/hackmac/disks.rb', line 33

def disk
  @disk
end