Class: Ramdisk
- Inherits:
-
Object
- Object
- Ramdisk
- Defined in:
- lib/ramdisk.rb
Overview
class that represents all information associated with a ram disk
Instance Attribute Summary collapse
-
#mountpoint ⇒ Object
Returns the value of attribute mountpoint.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ramdisk ⇒ Object
Returns the value of attribute ramdisk.
-
#size ⇒ Object
Returns the value of attribute size.
-
#system_interface ⇒ Object
Returns the value of attribute system_interface.
Instance Method Summary collapse
- #allocate(size) ⇒ Object
- #deallocate ⇒ Object
- #format(drivename = "ramdev", fileSystemFormat = :hfs) ⇒ Object
-
#initialize(mountpoint, system_interface = SystemInfo) ⇒ Ramdisk
constructor
A new instance of Ramdisk.
- #list ⇒ Object
- #mount ⇒ Object
- #mounted? ⇒ Boolean
- #unmount ⇒ Object
- #unmounted ⇒ Object
- #unmounted=(m) ⇒ Object
Constructor Details
#initialize(mountpoint, system_interface = SystemInfo) ⇒ Ramdisk
Returns a new instance of Ramdisk.
68 69 70 71 |
# File 'lib/ramdisk.rb', line 68 def initialize(mountpoint, system_interface = SystemInfo) self.mountpoint = mountpoint self.system_interface = system_interface end |
Instance Attribute Details
#mountpoint ⇒ Object
Returns the value of attribute mountpoint.
66 67 68 |
# File 'lib/ramdisk.rb', line 66 def mountpoint @mountpoint end |
#name ⇒ Object
Returns the value of attribute name.
66 67 68 |
# File 'lib/ramdisk.rb', line 66 def name @name end |
#ramdisk ⇒ Object
Returns the value of attribute ramdisk.
66 67 68 |
# File 'lib/ramdisk.rb', line 66 def ramdisk @ramdisk end |
#size ⇒ Object
Returns the value of attribute size.
66 67 68 |
# File 'lib/ramdisk.rb', line 66 def size @size end |
#system_interface ⇒ Object
Returns the value of attribute system_interface.
66 67 68 |
# File 'lib/ramdisk.rb', line 66 def system_interface @system_interface end |
Instance Method Details
#allocate(size) ⇒ Object
108 109 110 111 |
# File 'lib/ramdisk.rb', line 108 def allocate(size) sectors = size / 512 self.ramdisk = system_interface.hdiutil(sectors).strip end |
#deallocate ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/ramdisk.rb', line 113 def deallocate unmounted.each do |u| msg = system_interface.deallocate(u) if !msg =~ /.*unmounted\./ raise "ramdisk: #{u} failed to deallocate ramdisk with this message: #{msg}" end end unmounted = [] return true end |
#format(drivename = "ramdev", fileSystemFormat = :hfs) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/ramdisk.rb', line 124 def format(drivename = "ramdev", fileSystemFormat = :hfs) self.name = drivename case fileSystemFormat when :hfs msg = system_interface.newfs_hfs(name,ramdisk) if msg =~ /Initialized .*#{ramdisk[/\/*([^\/]*)$/,1]} as a/ return true else raise "ramdisk failed to format HFS volume #{ramdisk}" end else raise "ramdisk doesn't understand how to build #{fileSystemFormat} file system" end return flase end |
#list ⇒ Object
88 89 90 91 |
# File 'lib/ramdisk.rb', line 88 def list # cannot be ||= because state may have changed. @list = system_interface.ramdisks end |
#mount ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/ramdisk.rb', line 140 def mount if system_interface.mount(mountpoint, ramdisk) return true else puts "Unable to mount, trying again with 'sudo'" if system_interface.sudomount(mountpoint, ramdisk) return true else puts "ramdisk failed to mount" return false end end end |
#mounted? ⇒ Boolean
81 82 83 84 85 86 |
# File 'lib/ramdisk.rb', line 81 def mounted? list.each do |i| return true if i[1] =~ /#{mountpoint}$/ end return false end |
#unmount ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ramdisk.rb', line 154 def unmount unmounted_device = ramdisk if system_interface.unmount(mountpoint) unmounted.push(unmounted_device) return true else puts "Unable to unmount, trying again with 'sudo'." if system_interface.sudounmount(mountpoint, unmounted_device) return true else puts "ramdisk failed to un-mount." return false end end end |
#unmounted ⇒ Object
77 78 79 |
# File 'lib/ramdisk.rb', line 77 def unmounted @unmounted ||= [] end |
#unmounted=(m) ⇒ Object
73 74 75 |
# File 'lib/ramdisk.rb', line 73 def unmounted=(m) @unmounted = m end |