lib/industrialist/factory.rb in industrialist-0.4.0 vs lib/industrialist/factory.rb in industrialist-1.0.0
- old
+ new
@@ -1,26 +1,15 @@
-module Industrialist
- class Factory
- DEFAULT_KEY = :__manufacturable_default__
+require 'industrialist/builder'
- attr_reader :registry
-
- def initialize
- @registry = {}
+module Industrialist
+ module Factory
+ def manufactures(klass)
+ @type = Type.industrialize(klass)
end
- def register(key, klass)
- registry[factory_key(key)] = klass
- end
-
def build(key, *args)
- klass = registry[factory_key(key)] || registry[DEFAULT_KEY]
- klass&.new(*args)
- end
+ return if @type.nil?
- private
-
- def factory_key(key)
- (key.respond_to?(:to_sym) && key.to_sym) || key
+ Builder.build(@type, key, *args)
end
end
end