lib/dependor/auto_injector.rb in dependor-0.0.2 vs lib/dependor/auto_injector.rb in dependor-0.0.3

- old
+ new

@@ -8,29 +8,36 @@ end def get(name) ensure_resolvable!(name) - return @injector.send(name) if method_exists?(name) + if has_method?(name) + return @injector.send(name) if no_arguments?(name) + return @injector.method(name).to_proc + end klass = @class_name_resolver.for_name(name) @instantiator.instantiate(klass) end def resolvable?(name) - method_exists?(name) || !!@class_name_resolver.for_name(name) + has_method?(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) + def has_method?(name) @injector.methods.include?(name) + end + + def no_arguments?(name) + @injector.method(name).arity == 0 end end end