hackmac 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/hackmac/disks.rb CHANGED
@@ -1,26 +1,95 @@
1
1
  require 'hackmac/plist'
2
2
 
3
3
  module Hackmac
4
+ # A class that provides detailed information about a specific disk by
5
+ # querying the system's disk utility.
6
+ #
7
+ # The DiskInfo class interfaces with macOS's diskutil command to retrieve
8
+ # comprehensive details about a specified disk.
9
+ #
10
+ # @example
11
+ # disk_info = Hackmac::DiskInfo.new(disk: '/dev/disk0')
12
+ # # Provides access to disk information through method calls
4
13
  class DiskInfo
5
14
  include Hackmac::Plist
6
-
15
+ # The initialize method sets up a DiskInfo instance by retrieving detailed
16
+ # information about a specific disk.
17
+ #
18
+ # This method constructs and executes a system command to fetch
19
+ # comprehensive details about the specified disk using diskutil's info
20
+ # functionality with plist output format. The resulting plist data is
21
+ # parsed and made available for querying through dynamic method calls.
22
+ #
23
+ # @param disk [ String ] the disk identifier to retrieve information for
7
24
  def initialize(disk:)
8
25
  @disk = disk
9
- plist *(%w[ diskutil info -plist ] << disk)
26
+ plist(**(%w[ diskutil info -plist ] << disk))
10
27
  end
11
28
 
29
+ # The disk reader method provides access to the disk identifier that was
30
+ # used when initializing the DiskInfo instance.
31
+ #
32
+ # @return [ String ] the disk identifier associated with this instance
12
33
  attr_reader :disk
13
34
  end
14
35
 
36
+ # A class that provides access to comprehensive disk information by querying
37
+ # macOS's diskutil command
38
+ #
39
+ # The Disks class interfaces with the diskutil utility to retrieve detailed
40
+ # information about all disks in the system. It executes system commands to
41
+ # gather plist-formatted data about disk configurations and makes this
42
+ # information available through dynamic method calls for easy access and
43
+ # manipulation.
44
+ #
45
+ # @example
46
+ # disks = Hackmac::Disks.new
47
+ # # Provides access to disk information through method calls
15
48
  class Disks
16
49
  include Hackmac::Plist
17
50
 
51
+ # The initialize method sets up a Disks instance by executing a system
52
+ # command to retrieve comprehensive disk information.
53
+ #
54
+ # This method constructs and runs a shell command using the diskutil
55
+ # utility to fetch detailed information about all disks in the system. It
56
+ # processes the XML output, extends the resulting hash with deep find
57
+ # capabilities, and stores the largest matching result set in the instance
58
+ # variable.
59
+ #
60
+ # @param limiter [ String ] optional parameter to limit the output of diskutil list
61
+ # @param device [ String ] optional parameter to specify a particular device to query
18
62
  def initialize(limiter: nil, device: nil)
19
- plist *(%w[ diskutil list -plist ] + [ limiter, device ].compact)
63
+ plist(*(%w[ diskutil list -plist ] + [ limiter, device ].compact))
20
64
  end
21
65
  end
22
66
 
67
+ # A class that provides access to APFS container disk information by querying
68
+ # macOS's diskutil command
69
+ #
70
+ # The ContainerDisk class extends the Disks class to specifically retrieve
71
+ # and process information about Apple File System (APFS) containers
72
+ #
73
+ # This class initializes by taking a disk identifier and searching for the
74
+ # corresponding Apple_APFS device within the diskutil list output
75
+ #
76
+ # It then uses the APFS device path to construct a Disks instance, allowing
77
+ # access to detailed APFS container information through dynamic method calls
78
+ #
79
+ # @example
80
+ # container_disk = Hackmac::ContainerDisk.new(disk: '/dev/disk0')
81
+ # # Provides access to APFS container information through method calls
23
82
  class ContainerDisk < Disks
83
+ # The initialize method sets up a ContainerDisk instance by identifying and
84
+ # initializing with the APFS device associated with a given disk.
85
+ #
86
+ # This method takes a disk identifier and searches for the corresponding
87
+ # Apple_APFS device within the diskutil list output. It extracts the device
88
+ # path and passes it along to the parent Disks class constructor, allowing
89
+ # for further processing of APFS container information.
90
+ #
91
+ # @param disk [ String ] the disk identifier to search for APFS container device
92
+ # @param limiter [ String ] optional parameter to limit the output of diskutil list
24
93
  def initialize(disk:, limiter: nil)
25
94
  @disk = disk
26
95
  device = `#{Shellwords.join(%w[ diskutil list ] << disk)}`.
@@ -3,16 +3,43 @@ require 'json'
3
3
  require 'tins/string_version'
4
4
 
5
5
  module Hackmac
6
+ # A class that provides functionality for fetching and processing release
7
+ # information from GitHub repositories
8
+ #
9
+ # The GithubSource class enables interaction with GitHub's API to retrieve
10
+ # release data for a specified repository
11
+ #
12
+ # It parses release information to identify the latest version and provides
13
+ # methods for downloading associated assets
14
+ #
15
+ # @example
16
+ # source = Hackmac::GithubSource.new('owner/repo', auth: ['user', 'token'])
17
+ # # Fetches latest release information and allows asset downloads
6
18
  class GithubSource
7
19
  GITHUB_API_URL = 'https://api.github.com/repos/%s/releases'
8
20
 
9
21
  include Tins::StringVersion
10
22
 
23
+ # The initialize method sets up a GithubSource instance by fetching and
24
+ # parsing release information from the GitHub API.
25
+ #
26
+ # This method takes a GitHub repository identifier and optional
27
+ # authentication credentials, then retrieves all releases for that
28
+ # repository via the GitHub API. It processes the release data to find the
29
+ # highest version number, extracts relevant metadata about that release,
30
+ # and stores the release information for later use in downloading assets.
31
+ #
32
+ # @param github [ String ] the GitHub repository identifier in the format
33
+ # "owner/repo"
34
+ # @param auth [ Array<String>, nil ] optional basic authentication
35
+ # credentials [username, token]
36
+ # @param suffix [ String, nil ] optional suffix to filter asset names when
37
+ # downloading
11
38
  def initialize(github, auth: nil, suffix: nil)
12
39
  @github = github
13
40
  @auth = auth
14
41
  @suffix = (Regexp.quote(suffix) if suffix)
15
- account, repo = github.split(?/)
42
+ _account, repo = github.split(?/)
16
43
  @name = repo
17
44
  releases = URI.open(
18
45
  GITHUB_API_URL % github,
@@ -32,14 +59,54 @@ module Hackmac
32
59
  end
33
60
  end
34
61
 
62
+ # The name reader method provides access to the name attribute that was set
63
+ # during object initialization.
64
+ #
65
+ # This method returns the value of the name instance variable, which
66
+ # typically represents the descriptive identifier or label associated with
67
+ # the object.
68
+ #
69
+ # @return [ String ] the name value stored in the instance variable
35
70
  attr_reader :name
36
71
 
72
+ # The version reader method provides access to the version attribute that
73
+ # was set during object initialization.
74
+ #
75
+ # This method returns the value of the version instance variable, which
76
+ # typically represents the semantic version number associated with the
77
+ # object's current state or configuration.
78
+ #
79
+ # @return [ String, nil ] the version value stored in the instance variable, or nil if not set
37
80
  attr_reader :version
38
81
 
82
+ # The github reader method provides access to the github attribute that was
83
+ # set during object initialization.
84
+ #
85
+ # This method returns the value of the github instance variable, which
86
+ # typically represents the GitHub repository identifier in the format
87
+ # "owner/repo" associated with the object.
88
+ #
89
+ # @return [ String ] the github value stored in the instance variable
39
90
  attr_reader :github
40
91
 
92
+ # The auth reader method provides access to the auth attribute that was set
93
+ # during object initialization.
94
+ #
95
+ # This method returns the value of the auth instance variable, which
96
+ # typically represents authentication credentials used for accessing
97
+ # protected resources or services.
98
+ #
99
+ # @return [ Array<String>, nil ] the auth value stored in the instance variable, or nil if not set
41
100
  attr_reader :auth
42
101
 
102
+ # The download_asset method retrieves a compressed asset file from a GitHub
103
+ # release by finding the appropriate asset based on a suffix filter and
104
+ # downloading its contents
105
+ # as binary data
106
+ #
107
+ # @return [ Array<String, String>, nil ] returns an array containing the asset filename
108
+ # and downloaded data if successful, or nil if no suitable asset is found or
109
+ # if there is no release information available
43
110
  def download_asset
44
111
  @release or return
45
112
  asset = @release.assets.find { |a| a.name =~ /#@suffix.*\.(zip|tar\.gz)\z/i } or return
@@ -52,14 +119,30 @@ module Hackmac
52
119
  return asset.name, data
53
120
  end
54
121
 
122
+ # The inspect method returns a string representation of the object that
123
+ # includes its class name and string value
124
+ #
125
+ # @return [ String ] a formatted string containing the object's class name
126
+ # and its string representation
55
127
  def inspect
56
128
  "#<#{self.class}: #{to_s}>"
57
129
  end
58
130
 
131
+ # The to_s method returns a string representation of the object in the
132
+ # format "name version".
133
+ #
134
+ # @return [ String ] a formatted string containing the name and version
135
+ # separated by a space
59
136
  def to_s
60
137
  "#{name} #{version}"
61
138
  end
62
139
 
140
+ # The to_s method returns a string representation of the object by
141
+ # combining its name and version attributes into a single space-separated
142
+ # string.
143
+ #
144
+ # @return [ String ] a formatted string containing the name and version
145
+ # separated by a space
63
146
  def to_s
64
147
  "#{name} #{version}"
65
148
  end