Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instances are permanently modified at runtime when ':call' option is used #16

Closed
thebigw4lrus opened this issue Aug 20, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@thebigw4lrus
Copy link

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'
@thebigw4lrus thebigw4lrus added the bug Something isn't working label Aug 20, 2020
@iovis
Copy link
Contributor

iovis commented Aug 21, 2020

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 iovis self-assigned this Aug 21, 2020
@iovis
Copy link
Contributor

iovis commented Aug 21, 2020

Look into whether we can add dynamic refinements

@iovis
Copy link
Contributor

iovis commented Sep 1, 2020

Fixed in #17

@iovis iovis closed this as completed Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants