Module: Ejectable

Extended by:
DL::Importer
Defined in:
lib/ejectable.rb,
lib/ejectable/unix.rb,
lib/ejectable/device.rb,
lib/ejectable/windows.rb

Defined Under Namespace

Classes: Device, TrayHandleError

Constant Summary collapse

DEFAULT_DEVICE_NAME =
'cdaudio'.freeze

Class Method Summary collapse

Class Method Details

.close_tray(devname = DEFAULT_DEVICE_NAME) ⇒ Boolean

Raises:


17
18
19
# File 'lib/ejectable/unix.rb', line 17

def close_tray(devname=DEFAULT_DEVICE_NAME)
  system("eject -t #{devname}")
end

.close_tray!(devname = DEFAULT_DEVICE_NAME) ⇒ void


41
42
43
44
# File 'lib/ejectable.rb', line 41

def close_tray!(devname=DEFAULT_DEVICE_NAME)
  close_tray(devname) || raise(TrayHandleError)
  nil
end

.eject_tray(devname = DEFAULT_DEVICE_NAME) ⇒ Boolean


10
11
12
# File 'lib/ejectable/unix.rb', line 10

def eject_tray(devname=DEFAULT_DEVICE_NAME)
  system("eject #{devname}")
end

.eject_tray!(devname = DEFAULT_DEVICE_NAME) { ... } ⇒ void

This method returns an undefined value.

Yields:

  • close tray when exit block

Yield Returns:

  • (void)

Raises:


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ejectable.rb', line 25

def eject_tray!(devname=DEFAULT_DEVICE_NAME, &block)
  eject_tray(devname) || raise(TrayHandleError)

  if block_given?
    begin
      block.call
    ensure
      close_tray! devname
    end
  end

  nil
end