Sha256: fd13ccf2dcff4f9c3e0241fafddddae111db2aea8358b3c57ffa57a83b7f5bd2
Contents?: true
Size: 813 Bytes
Versions: 2
Compression:
Stored size: 813 Bytes
Contents
module Dependor class AutoInjector def initialize(injector, search_modules) @injector = injector @instantiator = Instantiator.new(self) @class_name_resolver = ClassNameResolver.new(search_modules) end def get(name) ensure_resolvable!(name) return @injector.send(name) if method_exists?(name) klass = @class_name_resolver.for_name(name) @instantiator.instantiate(klass) end def resolvable?(name) method_exists?(name) || !!@class_name_resolver.for_name(name) end private def ensure_resolvable!(name) unless resolvable?(name) raise UnknownObject.new("Injector does not know how to create object: #{name}") end end def method_exists?(name) @injector.methods.include?(name) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dependor-0.0.2 | lib/dependor/auto_injector.rb |
dependor-0.0.1 | lib/dependor/auto_injector.rb |