Class: Diskman::RootDevice

Inherits:
Device
  • Object
show all
Defined in:
lib/diskman/root_device.rb

Instance Attribute Summary

Attributes inherited from Device

#name, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Device

#get_clone_command, #get_fdisk_command, #get_mkfs_command, #get_write_command, #initialize

Constructor Details

This class inherits a constructor from Diskman::Device

Class Method Details

.chooseObject



13
14
15
16
17
# File 'lib/diskman/root_device.rb', line 13

def self.choose
    selection = Chooser.new(RootDevice.get_removable, item: 'removable device').select
    selection.ensure_not_mounted!
    selection
end

.get_removableObject



3
4
5
6
7
8
9
10
11
# File 'lib/diskman/root_device.rb', line 3

def self.get_removable
    Dir['/sys/block/*/removable'].select do |file|
        File.read(file).strip == '1'
    end.map do |path|
        path =~ %r[^/sys/block/(.*)/removable$]x && RootDevice.new($1)
    end.reject do |device|
        device.name =~ /sr\d+/
    end.sort
end

Instance Method Details

#choose_with_partitionsObject



19
20
21
# File 'lib/diskman/root_device.rb', line 19

def choose_with_partitions
    Chooser.new(get_with_partitions, item: 'block device').select
end

#ensure_not_mounted!Object



23
24
25
26
27
28
29
# File 'lib/diskman/root_device.rb', line 23

def ensure_not_mounted!
    if mounted?
        puts ('Warning: device appears to be mounted at ' + mount_point).yellow
        puts 'Not continuing'.red
        raise Interrupt
    end
end

#to_sObject



31
32
33
# File 'lib/diskman/root_device.rb', line 31

def to_s
    @path + ' [' + [size, label].reject(&:empty?).join(', ') + ']'
end