Class: BackupDemon::Device
- Inherits:
-
Object
- Object
- BackupDemon::Device
- Defined in:
- lib/backup_demon/device.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#mount_point ⇒ Object
readonly
Returns the value of attribute mount_point.
-
#mounted ⇒ Object
readonly
Returns the value of attribute mounted.
Class Method Summary collapse
Instance Method Summary collapse
- #different? ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(device) ⇒ Device
constructor
A new instance of Device.
- #mount(mount_point) ⇒ Object
- #mounted? ⇒ Boolean
- #unmount ⇒ Object
- #unmounted? ⇒ Boolean
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
#device ⇒ Object (readonly)
Returns the value of attribute device.
5 6 7 |
# File 'lib/backup_demon/device.rb', line 5 def device @device end |
#mount_point ⇒ Object (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 |
#mounted ⇒ Object (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
.mounted ⇒ Object
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
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
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
47 48 49 |
# File 'lib/backup_demon/device.rb', line 47 def mounted? Device.mounted.keys.include?(@device) end |
#unmount ⇒ Object
51 52 53 |
# File 'lib/backup_demon/device.rb', line 51 def unmount `umount #{@device}` end |
#unmounted? ⇒ Boolean
55 56 57 |
# File 'lib/backup_demon/device.rb', line 55 def unmounted? !mounted? end |