-
-
Save srushti/5985361 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PhysicalStorageVolume | |
OS_VERSION = RbConfig::CONFIG['host_os'] | |
def initialize(path) | |
@path = path | |
@path_exists = File.exists?(path) | |
end | |
def self.error_raising_method(name) | |
define_method(name) do |*args| | |
raise_error_if_file_doesnt_exist! | |
yield(*args) | |
end | |
end | |
def raise_error_if_file_doesnt_exist! | |
raise Errno::ENOENT.new(@path) unless @path_exists | |
end | |
error_raising_method :uuid do | |
@uuid ||= `diskutil info #{disk_name} | grep UUID`.split.last | |
end | |
error_raising_method :volume_label do | |
unless @volume_label | |
vname = 'Volume Name:' | |
vname_line = `diskutil info #{disk_name} | grep '#{vname}'` | |
@volume_label = vname_line.sub(vname, '').strip | |
end | |
@volume_label | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment