lib/industrialist/factory.rb in industrialist-0.3.0 vs lib/industrialist/factory.rb in industrialist-0.4.0

- old
+ new

@@ -1,7 +1,9 @@ module Industrialist class Factory + DEFAULT_KEY = :__manufacturable_default__ + attr_reader :registry def initialize @registry = {} end @@ -9,12 +11,14 @@ def register(key, klass) registry[factory_key(key)] = klass end def build(key, *args) - klass = registry[factory_key(key)] + klass = registry[factory_key(key)] || registry[DEFAULT_KEY] klass&.new(*args) end + + private def factory_key(key) (key.respond_to?(:to_sym) && key.to_sym) || key end end