lib/dependor/instantiator.rb in dependor-1.0.0 vs lib/dependor/instantiator.rb in dependor-1.0.1
- old
+ new
@@ -1,24 +1,15 @@
module Dependor
class Instantiator
- def initialize(injector)
+ attr_reader :dependency_names
+
+ def initialize(injector, dependency_names)
@injector = injector
- @constructor_params = {}
+ @dependency_names = dependency_names
end
def instantiate(klass)
- dependencies = dependecy_names_for(klass).map{|name| @injector.get(name)}
+ dependencies = dependency_names.for_class(klass).map{|name| @injector.get(name)}
return klass.new(*dependencies)
- end
-
- private
-
- def dependecy_names_for(klass)
- @constructor_params[klass] ||= get_constructor_params(klass)
- end
-
- def get_constructor_params(klass)
- params = klass.instance_method(:initialize).parameters
- params.select{|type, name| type == :req}.map{|type, name| name}
end
end
end