Skip to content

Instantly share code, notes, and snippets.

@srushti
Forked from jasim/physical_storage_volume.rb
Last active December 19, 2015 16:39
Show Gist options
  • Save srushti/5985361 to your computer and use it in GitHub Desktop.
Save srushti/5985361 to your computer and use it in GitHub Desktop.
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