Class: BackupDemon::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/backup_demon/device.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device) ⇒ Device

Returns a new instance of Device.



6
7
8
9
10
# File 'lib/backup_demon/device.rb', line 6

def initialize(device)
  @device = device
  @mounted = false
  @previous = nil
end

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



5
6
7
# File 'lib/backup_demon/device.rb', line 5

def device
  @device
end

#mount_pointObject (readonly)

Returns the value of attribute mount_point.



5
6
7
# File 'lib/backup_demon/device.rb', line 5

def mount_point
  @mount_point
end

#mountedObject (readonly)

Returns the value of attribute mounted.



5
6
7
# File 'lib/backup_demon/device.rb', line 5

def mounted
  @mounted
end

Class Method Details

.mountedObject



24
25
26
27
28
29
30
31
32
# File 'lib/backup_demon/device.rb', line 24

def self.mounted
  raw_mount_list = `mount`
  mount_list = {}
  raw_mount_list.split("\n").each do |line|
    items = line.split(' ')
    mount_list[items[0]] = items[2]
  end
  mount_list.select { |k, v| k =~ /^\/.*/} # only real devices
end

Instance Method Details

#different?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/backup_demon/device.rb', line 16

def different?
  begin      
    @previous != File.stat(@device)
  rescue
    false
  end
end

#exists?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/backup_demon/device.rb', line 12

def exists?
  File.exists?(@device)
end

#mount(mount_point) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/backup_demon/device.rb', line 34

def mount(mount_point)
  @mount_point = mount_point
  FileUtils.mkdir_p(@mount_point) unless File.exists?(@mount_point)
  `mount #{@device} #{@mount_point}`
  
  if mounted?
    @previous = File.stat(@device)
    true
  else
    false
  end
end

#mounted?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/backup_demon/device.rb', line 47

def mounted?
  Device.mounted.keys.include?(@device)
end

#unmountObject



51
52
53
# File 'lib/backup_demon/device.rb', line 51

def unmount
  `umount #{@device}`
end

#unmounted?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/backup_demon/device.rb', line 55

def unmounted?
  !mounted?
end