Class: Norn::ModeRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/norn/mode_registry.rb

Class Method Summary collapse

Class Method Details

.clear!Object



44
45
46
47
48
49
# File 'lib/norn/mode_registry.rb', line 44

def clear!
  @lock.synchronize do
    @modes.clear
    @descriptions.clear
  end
end

.description_for(name) ⇒ Object



40
41
42
# File 'lib/norn/mode_registry.rb', line 40

def description_for(name)
  @lock.synchronize { @descriptions[name.to_s] }
end

.register(name, mode_class, description: "") ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/norn/mode_registry.rb', line 10

def register(name, mode_class, description: "")
  # Enforce subclassing contract
  unless mode_class < Norn::Mode
    raise Norn::Error, "Registration Failure: Mode '#{name}' (#{mode_class}) must inherit from Norn::Mode"
  end

  # Enforce abstract method contract
  missing_methods = Norn::Mode::ABSTRACT_METHODS.reject do |method|
    mode_class.instance_methods.include?(method) && 
      mode_class.instance_method(method).owner != Norn::Mode
  end

  unless missing_methods.empty?
    raise Norn::Error, "Interface Violation: Mode class #{mode_class} must implement abstract methods: #{missing_methods.join(', ')}"
  end

  @lock.synchronize do
    @modes[name.to_s] = mode_class
    @descriptions[name.to_s] = description
  end
end

.registered_modesObject



36
37
38
# File 'lib/norn/mode_registry.rb', line 36

def registered_modes
  @lock.synchronize { @modes.keys }
end

.resolve(name) ⇒ Object



32
33
34
# File 'lib/norn/mode_registry.rb', line 32

def resolve(name)
  @lock.synchronize { @modes[name.to_s] }
end