mitchellh / virtualbox

[ABANDONED] Create and modify virtual machines in VirtualBox using pure ruby.
http://mitchellh.github.com/virtualbox/
MIT License
245 stars 45 forks source link

AbstractEnums take a hash of keys and common names #13

Closed KieranP closed 14 years ago

KieranP commented 14 years ago

It would be good if AbstractEnums took a hash, comprised of keys, and their command names. In vboxweb_rb, I have to make this mapping manually, which it very incomplete.

def boot_types
  [ ['None', 'null'],
    ['Floppy', 'floppy'],
    ['CD / DVD-ROM', 'dvd'],
    ['Hard Disk', 'hard_disk'],
    ['Network', 'network'] ]
end

def audio_drivers
  [ ['None', 'none'],
    ['Null Audio Driver', 'null'],
    ['CoreAudio', 'core_audio'] ]
end

etc....

The idea is to be able to pass this off to the virtualbox gem.

map {
  :none => 'None',
  :null => 'Null Audio Driver',
  :core_audio => 'Core Audio'
}

Then:

vm.audio_adapter.audio_driver => :core_audio
vm.audio_adapter.audio_driver_name => "Core Audio"
mitchellh commented 14 years ago

I was looking at how VirtualBox GUI and such do this and it looks like they use a lookup table of their own so I'd like to leave this to application developers. In general, the symbols will be more useful unless you're displaying it, which I think is a special case with your vbox_web =] I recommend using Rails i18n to make this easier for you.

Mitchell

KieranP commented 14 years ago

Alright, thanks. I went ahead as you suggested and used I18n.

The result:

http://github.com/KieranP/vboxweb_rb/commit/3fba1894b78263deebbeadd31c891f4213081c09

http://github.com/KieranP/vboxweb_rb/blob/master/config/locales/en.yml