Class: MongoTestServer::RamDiskStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_test_server/ram_disk_storage.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ RamDiskStorage

Returns a new instance of RamDiskStorage.



13
14
15
16
# File 'lib/mongo_test_server/ram_disk_storage.rb', line 13

def initialize(name)
  @name = "#{name}-mongo-ram-disk"
  @path = "/Volumes/#{@name}"
end

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/mongo_test_server/ram_disk_storage.rb', line 8

def supported?
  `which hdiutil`!=''
end

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
# File 'lib/mongo_test_server/ram_disk_storage.rb', line 18

def create
  @ram_disk_device ||= lambda {
    device = `hdiutil attach -nomount ram://1000000`.chomp
    `diskutil erasevolume HFS+ #{@name} #{device}`
    device
    }.call
  path
end

#deleteObject



31
32
33
34
# File 'lib/mongo_test_server/ram_disk_storage.rb', line 31

def delete
  `umount #{path} 2> /dev/null`
  `hdiutil detach #{@ram_disk_device} 2> /dev/null`
end

#pathObject



27
28
29
# File 'lib/mongo_test_server/ram_disk_storage.rb', line 27

def path
  @path
end