These are chat archives for dry-rb/chat

27th
Aug 2017
Stergio
@stergiom
Aug 27 2017 10:57
@eriknelson if using Container and AutoInject directly you'll have to take care of the requires' somehow, I don't know if there is a canonical way of going about this, but I gravitated towards creating all Containers and AutoInject namespaces first, then using some or other require-all approach (possibly per directory/namespace grouping) and finally taking care of all container registrations. You might want to look at Dry-System, its neat for taking care of ^this
Stergio
@stergiom
Aug 27 2017 17:17
class FreshRocker < Rocker
  include Inject[:fruit_basket, :top_drawer]

  def initialize(beat:, **injected)
    #super(injected)  #for auto_inject
    blend = [fruit_basket.apple, fruit_basket.pineapple, top_drawer.pen]
    super(the_beat: beat, the_blend: blend)
  end
end
Using inheritance along with auto_inject, is there a way to explicitly pass injected on to auto_inject? something along the lines of ?.instance_method(:?).bind(self).call(injected) as a type of scoped-super?
Nikita Shilnikov
@flash-gordon
Aug 27 2017 19:47
@stergiom just grap dependencies from injected, i.e. blend = [injected[:fruit_basket].apple, injected[:fruit_basket].pineapple, injected[:top_drawer].pen]
then call super(**injected, the_beat: beat, the_blend: blend)
Stergio
@stergiom
Aug 27 2017 20:04
thanks @flash-gordon, I'd have to manually set getters up for the injected though (wanting to use them with other methods), looking for a way to explicitly let the auto_inject module know to do its thing
thought there might be a way to invoke the relative method on auto_inject with injected for such cases
Nikita Shilnikov
@flash-gordon
Aug 27 2017 20:07
dry-auto_inject does nothing more than defining the initialize method on the instance level, you call it with super, that's it
you can assign attributes yourself, then call super, dry-auto_inject just will set them once again
def initialize(fruit_basket:, top_drawer:, **rest)
  super(rest)
  @fruit_basket = fruit_basket
  @top_drawer = top_drawer
end
that's how the auto-generated constructor looks like^ nothing more than this
Stergio
@stergiom
Aug 27 2017 20:10
ahh.. I thought it set getters up too
Nikita Shilnikov
@flash-gordon
Aug 27 2017 20:11
ugh, yeah, it defines attr_reader :fruit_basket, :top_drawer :grin:
but that happens on the class-level, technically speaking
Stergio
@stergiom
Aug 27 2017 20:12
:-) its all that which I'd like to get it to do, it works with super(rest) as long as there's no inheritance, but in the initial example where super is used down bottom it breaks
Nikita Shilnikov
@flash-gordon
Aug 27 2017 20:15
nah, just write @fruit_basket, @top_drawer = injected.values_at(:fruit_basket, :top_drawer) at the first line of your constructor, keep it simple :)
then
    blend = [fruit_basket.apple, fruit_basket.pineapple, top_drawer.pen]
    super(the_beat: beat, the_blend: blend, **injected)
and this is it. Yes, dry-auto_inject wil assign attributes with the same values once again but this is a minor issue compared to using metaprogramming
Stergio
@stergiom
Aug 27 2017 20:19
:+1: done
Nikita Shilnikov
@flash-gordon
Aug 27 2017 20:19
awesome :)