Sha256: 51df8e42304d15fe4a138565049128b63d0a3a1987918106f3a4b4928d0c7cab

Contents?: true

Size: 598 Bytes

Versions: 1

Compression:

Stored size: 598 Bytes

Contents

module Dependor
  class Instantiator
    def initialize(injector)
      @injector = injector
      @constructor_params = {}
    end

    def instantiate(klass)
      dependencies = dependecy_names_for(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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dependor-1.0.0 lib/dependor/instantiator.rb