Class: Industrialist::Registrar

Inherits:
Object
  • Object
show all
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

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_typesObject



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