These are chat archives for dry-rb/chat

20th
Aug 2015
Piotr Solnica
@solnic
Aug 20 2015 09:23
@AMHOL do we want dry-auto_inject or just add AutoInject extension to dry-container (ie Dry::Container::AutoInject)??
Andy Holland
@AMHOL
Aug 20 2015 09:27
I'd go with a separate repo
WDYT?
Piotr Solnica
@solnic
Aug 20 2015 09:27
hmm probably dry-auto_inject would be better
haha lol right
Andy Holland
@AMHOL
Aug 20 2015 09:28
:+1:
Piotr Solnica
@solnic
Aug 20 2015 09:28
yeah, it can be “container agnostic"
Andy Holland
@AMHOL
Aug 20 2015 09:28
Yeah, container could just be a hash really :)
Piotr Solnica
@solnic
Aug 20 2015 09:28
yep
Piotr Solnica
@solnic
Aug 20 2015 10:48
@AMHOL I just wrote the most crazy ruby code ever
Andy Holland
@AMHOL
Aug 20 2015 10:49
:laughing: ?
@solnic don't do that :p
I've got this really interesting thing to tell you and I know you're interested
AMHOL @AMHOL leaves
Andy Holland
@AMHOL
Aug 20 2015 10:52
:laughing:
Piotr Solnica
@solnic
Aug 20 2015 10:57
Dry::AutoInject
  works

Finished in 0.00313 seconds (files took 0.20784 seconds to load)
1 example, 0 failures
HELL YEAH
Andy Holland
@AMHOL
Aug 20 2015 10:58
:D
Piotr Solnica
@solnic
Aug 20 2015 10:58
pushing, you’re gonna be like “OMG WTF"
Andy Holland
@AMHOL
Aug 20 2015 10:58
haha
Piotr Solnica
@solnic
Aug 20 2015 10:58
but it’s lovely
Andy Holland
@AMHOL
Aug 20 2015 10:58
So a good WTF?
Piotr Solnica
@solnic
Aug 20 2015 11:00
very good, but batshit crazy
:joy:
Andy Holland
@AMHOL
Aug 20 2015 11:01
Got configurable in there too :D
Piotr Solnica
@solnic
Aug 20 2015 11:01
right, not sure if good idea though
although it handled inheritance nicely
so that’s a plus
I’ll leave it for now
Andy Holland
@AMHOL
Aug 20 2015 11:03
Wow, think I'm gonna have to read this a few times before it sinks in
Piotr Solnica
@solnic
Aug 20 2015 11:03
inorite
I don’t get it, but it works :joy_cat:
Andy Holland
@AMHOL
Aug 20 2015 11:03
:laughing:
Gonna grab some food, will try and get my head around it during lunch :p
Would be good to get @andypike's opinion too?
Piotr Solnica
@solnic
Aug 20 2015 11:06
totally
Piotr Solnica
@solnic
Aug 20 2015 11:27
trying to use it in my app at work, rails env got stuck while booting lol
I guess it’s because I left byebug in dry-auto_inject :joy:
IT IS WORKING
Piotr Solnica
@solnic
Aug 20 2015 11:33
some issues with configurable but in general it’s working ;)
NoMethodError:
  undefined method `synchronize' for nil:NilClass
# /home/vagrant/.gem/ruby/2.2.0/gems/dry-configurable-0.1.1/lib/dry/configurable.rb:42:in `config’
it’s ok actually, this seems like an overkill to use configurable
anyhow, this is close to be good enough for 0.0.1
Andy Holland
@AMHOL
Aug 20 2015 11:42
Cool, need to figure out what's going on with dry-config
Piotr Solnica
@solnic
Aug 20 2015 11:50
@AMHOL don’t, I shouldn’t have used it
it’s an issue with the way I did that
Andy Holland
@AMHOL
Aug 20 2015 11:50
@solnic WDYT of defaulting the args in the constructor rather than overriding .new ?
Ahh OK
Piotr Solnica
@solnic
Aug 20 2015 11:50
I just replaced it with an ivar
works, with inheritance too
@AMHOL I like keeping constructors clean :)
Andy Holland
@AMHOL
Aug 20 2015 11:51
I was thinking it would be good to still be able to use the class as normal and inject the dependencies
Piotr Solnica
@solnic
Aug 20 2015 11:52
you can do MyClass.new(nil, ‘foo’) and first arg will be injected
not super beautiful I have to admit
but works
not sure how to approach this better
maybe a single hash as an arg would be nicer I dunno
Andy Holland
@AMHOL
Aug 20 2015 11:52
Yeah, without container resolution as the point of entry it's difficult
Piotr Solnica
@solnic
Aug 20 2015 11:52
or kw args for newer rubies
Andy Holland
@AMHOL
Aug 20 2015 11:53
Yeah, although a bit obtrusive to enforce that
Piotr Solnica
@solnic
Aug 20 2015 11:53
right
in specs if you wanted to mock something you could stub container resolution, right?
not sure what the best practice should be
sth to discover I suppose
Andy Holland
@AMHOL
Aug 20 2015 11:55
Yeah
Thinking the currying library could help
In fact, if it was all-or-nothing, it shouldn't be too difficult
class MyClass
  include Dry::AutoInject[:user_repository, :current_user]

  def initialize(repository, user, user_attributes)
    # ...
  end
end

# args length is the same as (required args - injected args) (resolve)
MyClass.new(name: 'Jack')
# args length is greater than as (required args - injected args) (don't resolve or arg error)
MyClass.new(user_repo, current_user, name: 'Jill')
Andy Holland
@AMHOL
Aug 20 2015 12:00
sth like that
Piotr Solnica
@solnic
Aug 20 2015 12:01
we’ll see, now I gotta fix inheritance, as it’s not there yet as it just turned out
Andy Holland
@AMHOL
Aug 20 2015 12:01
Ahh OK, cool
Piotr Solnica
@solnic
Aug 20 2015 12:09
gaaah inheritance :worried:
Piotr Solnica
@solnic
Aug 20 2015 12:23
ok fixed that
Piotr Solnica
@solnic
Aug 20 2015 12:28
@AMHOL btw any thoughts on memoization in container?
I’ve got a lot of objects that can be safely memoized in the process
now they are created on each request
in fact, most of my objects can be memoized
hahaha all specs are green in my app :)
Andy Holland
@AMHOL
Aug 20 2015 12:33
Nice :D
Piotr Solnica
@solnic
Aug 20 2015 12:33
dryrb/dry-auto_inject@7626379
drastically simplified
there was no need for second mixin
Andy Holland
@AMHOL
Aug 20 2015 12:34
Cool, much better
Will have to have a think about memoization, something feels wrong about it
Sorry, got an urgent bugfix so will have to have a proper look later
Piotr Solnica
@solnic
Aug 20 2015 12:48
crazy or not, green on travis: https://travis-ci.org/dryrb/dry-auto_inject
pushing 0.0.1
Andy Holland
@AMHOL
Aug 20 2015 12:49
Cool, :shipit:
Piotr Solnica
@solnic
Aug 20 2015 12:55
released 0.0.1
Kris Leech
@krisleech
Aug 20 2015 13:29
I wrote a lib similar to AutoInject, Medicine, I'm intrested to see the implimention, I found it quite tricky.
One thing I couldn't figure out is how to have the dependency avalible as class, so if you inject my_model as well as a method my_model you also get MyModel, which looks like you aren't even using dependency injection (if that makes sense).
I don't think you can create constants on singelton classes, so they only way might be to have a method such as define_method MyModel.
Piotr Solnica
@solnic
Aug 20 2015 13:42
@krisleech that should raise imo
I use strict constructor injection as the only way a given object can get its dependencies
Andy Holland
@AMHOL
Aug 20 2015 14:50
@krisleech the idea with IoC is that you don't need to reference one class from the other (a hard dependency), you should just be able to constructor inject (loose/interface) dependencies and use those inside of your object
Piotr Solnica
@solnic
Aug 20 2015 14:51
@AMHOL we’re running on dry-auto_inject already :)
I’ll add dry-curry + extend dry-pipeline with * operator (classical fn composition) and we could add a logo and maybe start promoting things here and there
those are really cool libs :)
Andy Holland
@AMHOL
Aug 20 2015 14:52
Also, the injection should have minimal impact on the classes code, the container should, really, unobtrusively inject the dependencies without the need for any modifications (i.e. the class should be able to be used stand-alone the same way it would if the container wasn't present), this is impossible to achieve without the container being your entry point
@solnic in production?
Yeah, dry-curry should be mega useful
Any ideas where to get a logo from? And how much it will cost?
Piotr Solnica
@solnic
Aug 20 2015 14:54
@AMHOL I’ll start by asking my friend designers :)
@AMHOL no, on staging, production next Monday :D
Andy Holland
@AMHOL
Aug 20 2015 14:55
Nice
Was it a friend that did the ROM logo?
Piotr Solnica
@solnic
Aug 20 2015 14:55
yeah, which reminds me we gotta add info about that to the footer
and I know few more
Kris Leech
@krisleech
Aug 20 2015 14:56
@solnic @AMHOL The idea was not to hard reference another class, but for it to look like you are, normally you might do MyModel.find, with dependency injection it would be my_model.find. My idea was to define a method, not class, called MyModel so it looked visually the same with DI as without.
Andy Holland
@AMHOL
Aug 20 2015 14:59
Would be better to just inject the object returned from MyModel.find or inject the "repository" in the constructor IMO, would get confusing if it looked like a hard dependency too