Class: MIDIator::DriverRegistry
- Inherits:
-
Object
- Object
- MIDIator::DriverRegistry
- Includes:
- Singleton
- Defined in:
- lib/midiator/driver_registry.rb
Instance Method Summary collapse
-
#[](name) ⇒ Object
Included to make the registry quack like a hash.
-
#register_driver(name, klass) ⇒ Object
(also: #register, #<<)
Stores the given
klass
in the@drivers
hash, keyed byname
. -
#size ⇒ Object
Returns the number of drivers currently registered.
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.
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 |
#size ⇒ Object
Returns the number of drivers currently registered.
42 43 44 |
# File 'lib/midiator/driver_registry.rb', line 42 def size return @drivers.size end |