Class: MIDIator::DriverRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/midiator/driver_registry.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object

Included to make the registry quack like a hash. Delegates to the @drivers hash.



49
50
51
# File 'lib/midiator/driver_registry.rb', line 49

def []( name )
  return @drivers[ name ]
end

#register_driver(name, klass) ⇒ Object Also known as: register, <<

Stores the given klass in the @drivers hash, keyed by name. Typically called via MIDIator::Driver’s inherited hook.

Raises:

  • (ArgumentError)


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

def register_driver( name, klass )
  @drivers ||= {}

  raise ArgumentError, "Attempted to register something that is not a MIDIator::Driver" unless
    klass < MIDIator::Driver

  @drivers.each do |existing_name, existing_klass|
    raise ArgumentError, "Already registered #{existing_klass.to_s} as '#{existing_name}'." if
      existing_klass == klass
  end

  @drivers[ name ] = klass
end

#sizeObject

Returns the number of drivers currently registered.



42
43
44
# File 'lib/midiator/driver_registry.rb', line 42

def size
  return @drivers.size
end