These are chat archives for dry-rb/chat

25th
May 2017
Stergio
@stergiom
May 25 2017 11:26
class TheClass < SomeOtherClass
    def initialize(some_dep:)
        super()
        @some_dep = some_dep
    end
end

Using auto_inject this becomes..

class TheClass < SomeOtherClass
    include Inject[:some_dep]

    def initialize(*)
        super
    end
end

The initial example calls super with no arguments, with auto_inject in the mix does the parent class receive arugments?

Nikita Shilnikov
@flash-gordon
May 25 2017 13:17
@stergiom yes, the gem does its best to match the parent's arguments, but this is not always possible IIRC
Stergio
@stergiom
May 25 2017 13:22
@flash-gordon, so would passing a specific parameter to a parent like this suffice?
class TheClass < SomeOtherClass
    include Inject[:some_dep]

    def initialize(*)
        super(only_for_parent)
    end
end
Nikita Shilnikov
@flash-gordon
May 25 2017 13:25
I'd expect something like this to work
class TheClass < SomeOtherClass
  include Inject[:some_dep]

  def initialize(**kwargs)
    super(only_for_parent, kwargs)
  end
end
Stergio
@stergiom
May 25 2017 13:27
:100: I’ll give it some playtime..
thanks
Stergio
@stergiom
May 25 2017 21:23
I have a few classes using auto_inject for dependencies in the same container and have to keep track of the order they get require'd and register'd, is there a way to get dynamic component resolution with dry-container short of using dry-system?
Nikita Shilnikov
@flash-gordon
May 25 2017 21:55
@stergiom well, you can just register them manually with a simple directory traverse and register(key) { require full_path; constantize(full_path).new }