Class: Ramdo::DiskInstance
- Inherits:
-
Object
- Object
- Ramdo::DiskInstance
- Defined in:
- lib/ramdo/disk_instance.rb
Constant Summary collapse
- NAME_PATTERN =
/^ramdo_disk_([a-z0-9]+)$/
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy! ⇒ Object
-
#initialize(path) ⇒ DiskInstance
constructor
A new instance of DiskInstance.
Constructor Details
#initialize(path) ⇒ DiskInstance
Returns a new instance of DiskInstance.
29 30 31 |
# File 'lib/ramdo/disk_instance.rb', line 29 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
27 28 29 |
# File 'lib/ramdo/disk_instance.rb', line 27 def path @path end |
Class Method Details
.create ⇒ Object
16 17 18 19 20 21 |
# File 'lib/ramdo/disk_instance.rb', line 16 def self.create path = File.join('/tmp', self.generate_name) Dir.mkdir(path) self.new(path) end |
.generate_name ⇒ Object
23 24 25 |
# File 'lib/ramdo/disk_instance.rb', line 23 def self.generate_name "ramdo_disk_#{SecureRandom.hex(4)}" end |
.list ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ramdo/disk_instance.rb', line 5 def self.list disks = [] Dir.glob('/tmp/*').each do |dir| if (dir.split(File::SEPARATOR).last =~ NAME_PATTERN) && File.writable?(dir) disks << self.new(dir) end end disks end |
Instance Method Details
#destroy! ⇒ Object
33 34 35 36 |
# File 'lib/ramdo/disk_instance.rb', line 33 def destroy! return false unless Dir.exist? @path FileUtils.rm_r @path, :force => true end |