Instances are permanently modified at runtime when ':call' option is used
Closed this issue · 3 comments
thebigw4lrus commented
Context
Declaring a dependency with the ':call' option, and using this class two times in the same execution process.
Problem
It seems that the declared dependencies are permanently modified as 'call' method is added to them. This ends up in a Injectable::MethodAlreadyExistsException
as Injectable is actually checking that the call method does not exist in the dependency when it tries to do the monkey patch.
How to recreate it
[5] pry(main)> class SomeClass
[5] pry(main)* include Injectable
[5] pry(main)* dependency(:dep, call: :name) { Object }
[5] pry(main)* def call
[5] pry(main)* dep.call
[5] pry(main)* end
[5] pry(main)* end
=> :call
[6] pry(main)> SomeClass.call
=> "Object"
[7] pry(main)> SomeClass.call
Injectable::MethodAlreadyExistsException: Injectable::MethodAlreadyExistsException
from /Library/Ruby/Gems/2.6.0/gems/injectable-2.0.0/lib/injectable/dependency.rb:20:in `wrap_call'
iovis commented
It seems like when the target is a class, the :call
method is being persisted. I'll have to think of a less permanent way of adding that :call
aliasing
iovis commented
Look into whether we can add dynamic refinements