class Industrialist::Registrar
Constants
- DEFAULT_KEY
- REDEFINED_DEFAULT_WARNING_MESSAGE
- REDEFINED_KEY_WARNING_MESSAGE
Public Class Methods
register(type, key, klass)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/industrialist/registrar.rb, line 33 def registered_keys(type) registry[type].keys end
registered_types()
click to toggle source
# File lib/industrialist/registrar.rb, line 29 def registered_types registry.keys end
value_for(type, key)
click to toggle source
# 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
Private Class Methods
overriding?(type, key, klass)
click to toggle source
# File lib/industrialist/registrar.rb, line 43 def overriding?(type, key, klass) !registry[type][key].nil? && registry[type][key].name != klass.name end
registry()
click to toggle source
# File lib/industrialist/registrar.rb, line 47 def registry @registry ||= Hash.new { |hash, key| hash[key] = {} } end
registry_key(key)
click to toggle source
# File lib/industrialist/registrar.rb, line 39 def registry_key(key) (key.respond_to?(:to_sym) && key.to_sym) || key end