Class: Industrialist::Registrar
- Inherits:
-
Object
- Object
- Industrialist::Registrar
- Defined in:
- lib/industrialist/registrar.rb
Constant Summary collapse
- DEFAULT_KEY =
:__manufacturable_default__
- REDEFINED_KEY_WARNING_MESSAGE =
'warning: overriding a previously registered class'.freeze
- REDEFINED_DEFAULT_WARNING_MESSAGE =
'warning: overriding a previously registered default class'.freeze
Class Method Summary collapse
- .register(type, key, klass) ⇒ Object
- .register_default(type, klass) ⇒ Object
- .registered_keys(type) ⇒ Object
- .registered_types ⇒ Object
- .value_for(type, key) ⇒ Object
Class Method Details
.register(type, key, klass) ⇒ Object
11 12 13 14 15 |
# File 'lib/industrialist/registrar.rb', line 11 def register(type, key, klass) WarningHelper.warning(REDEFINED_KEY_WARNING_MESSAGE) if overriding?(type, key, klass) registry[type][registry_key(key)] = klass end |
.register_default(type, klass) ⇒ Object
17 18 19 20 21 |
# File 'lib/industrialist/registrar.rb', line 17 def register_default(type, klass) WarningHelper.warning(REDEFINED_DEFAULT_WARNING_MESSAGE) if overriding?(type, DEFAULT_KEY, klass) registry[type][DEFAULT_KEY] = klass end |
.registered_keys(type) ⇒ Object
33 34 35 |
# File 'lib/industrialist/registrar.rb', line 33 def registered_keys(type) registry[type].keys end |
.registered_types ⇒ Object
29 30 31 |
# File 'lib/industrialist/registrar.rb', line 29 def registered_types registry.keys end |
.value_for(type, key) ⇒ Object
23 24 25 26 27 |
# File 'lib/industrialist/registrar.rb', line 23 def value_for(type, key) return unless registry.key?(type) registry[type][registry_key(key)] || registry[type][DEFAULT_KEY] end |