lib/invokr/dependency_injection.rb in invokr-0.9.6 vs lib/invokr/dependency_injection.rb in invokr-0.9.7
- old
+ new
@@ -2,11 +2,11 @@
module DependencyInjection
extend self
def inject obj, using
meth = case obj
- when lambda { |obj| obj.respond_to?(:call) } then :inject_proc
+ when lambda { |obj| proc? obj } then :inject_proc
when Class then :inject_klass
else raise ArgumentError, "can't inject #{obj.inspect}"
end
resolver = build_resolver using
send meth, obj, resolver
@@ -28,9 +28,13 @@
end
def inject_proc proc, resolver
injector = ProcInjector.new resolver, proc
injector.inject
+ end
+
+ def proc? object
+ object.respond_to? :call and object.respond_to? :to_proc
end
Injector = Struct.new :resolver, :obj do
def keys
method.parameters.map { |_, identifier| identifier }