rubiconmd / injectable

Opinionated and declarative Dependency Injection library for ruby.
https://rubygems.org/gems/injectable
MIT License
34 stars 5 forks source link

Use dynamic modules to allow correct `call` inheritance #20

Closed rewritten closed 2 years ago

rewritten commented 4 years ago

This should close #19

With this change, the ancestors of a subclass of a service are:

puts my_service_instance.class.ancestors
# SubClass::InjectableCallFacade
# SubClass
# Injectable::InstanceMethods
# SuperClass::InjectableCallFacade
# SuperClass
# Injectable
# Object
# Kernel
# BasicObject

Each concrete class over Injectable gets a dynamically generated module, with a :call implementation that

This way we have an alternating chain of methods (one in the facade and one in the concrete class) that call each other.

The dynamically generated module does not need to be assigned to a constant, but it helps when reading traces.

codeclimate[bot] commented 4 years ago

Code Climate has analyzed commit a7ae61e0 and detected 12 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 8
Style 4

View more on Code Climate.