These are chat archives for dry-rb/chat

14th
Oct 2017
Piotr Solnica
@solnic
Oct 14 2017 07:53
@splattael boot/import/container are part of system configuration so we keep them separated
Peter Leitzen
@splattael
Oct 14 2017 08:38
@solnic Yes. I thought MyApp:: Container should live in lib/ as it's used by the application code. Is system/ shipped like lib/ is?
Piotr Solnica
@solnic
Oct 14 2017 08:39
@splattael I'd say container is your application
it's the entry point
ie you can do this:
∞ [ruby-2.4.2][node-v8.7.0] app git(master) ✗ pry -r ./system/app/container.rb
[1] pry(main)> App::Container[:logger]
=> #<Dry::Monitor::Logger:0x00007fed0ede0bb8...
it doesn't load the web part at all, you're not loading any code except container file (and its dependencies)
and when you ask for something, like this logger, it's gonna load it on demand
so, an entry point :)
Peter Leitzen
@splattael
Oct 14 2017 08:42
:+1: Got it. My question is why it's not in lib/?
Piotr Solnica
@solnic
Oct 14 2017 08:43
because we use lib for auto-registration, and it's conceptually a different thing than things defined under lib
just like rails keeps its config stuff under config, we keep kind-of-similar stuff under system
Peter Leitzen
@splattael
Oct 14 2017 08:45
Mh, ok. I wonder how other components would use my component? Do they have to load my system/APP/container?
@solnic (Please excuse my confusion %)
Piotr Solnica
@solnic
Oct 14 2017 08:47
@splattael wdym by other components?
Peter Leitzen
@splattael
Oct 14 2017 08:47
With "component" I mean gem.
Piotr Solnica
@solnic
Oct 14 2017 08:48
no, gems should not know about your container. They don’t depend on it
If you need go set up an external library (a gem) then you can use bootable components
I actually just finished working on a huge new feature which allows you to have a gem which can provide bootable components for dry-system apps (and improved boot dsl at the same time as a bonus)
Peter Leitzen
@splattael
Oct 14 2017 08:50
Nice!
Piotr Solnica
@solnic
Oct 14 2017 08:50
check out the pr in repo. I added a looong description which might be interesting to you
Peter Leitzen
@splattael
Oct 14 2017 08:50
@solnic awesome, will do!
Piotr Solnica
@solnic
Oct 14 2017 08:51
dry-rb/dry-system#61
this one
Peter Leitzen
@splattael
Oct 14 2017 08:51
How do I expose services from my gem? I thought MyApp::Container would it.
Piotr Solnica
@solnic
Oct 14 2017 08:52
you boot them and register their objects in your container
Peter Leitzen
@splattael
Oct 14 2017 08:52
So I require system/boot/MY_GEM?
Piotr Solnica
@solnic
Oct 14 2017 08:53
no, container takes care of requiring files
Peter Leitzen
@splattael
Oct 14 2017 08:55
I think I need examples :/
Do you have anything I can look at?
Peter Leitzen
@splattael
Oct 14 2017 09:01
To be more concrete: Examples where component A is using component B and they do NOT live in the same system/ directory. Read: separate gems.
Piotr Solnica
@solnic
Oct 14 2017 09:30
@splattael well if A needs B then A should take care of booting details and load B
Peter Leitzen
@splattael
Oct 14 2017 09:32
Does A know B's Container?
Piotr Solnica
@solnic
Oct 14 2017 09:43
@splattael wait, I think you need to tell me more about your gems
Peter Leitzen
@splattael
Oct 14 2017 09:43
I need to show THE CODE.
Piotr Solnica
@solnic
Oct 14 2017 09:43
I’m on mobile btw, so a bit harder to type ;)
Peter Leitzen
@splattael
Oct 14 2017 10:07
Me too and also on a conference...
Peter Leitzen
@splattael
Oct 14 2017 12:24
@solnic I've created a repo to show "my problem": https://github.com/splattael/test-dry-system
Piotr Solnica
@solnic
Oct 14 2017 12:55
@splattael ah so your gem is a system, in that case, you can just boot it and import its components into your container. ie require "my_gem/boot" and then App::Container.import(my_gem: MyGem::Container)
Peter Leitzen
@splattael
Oct 14 2017 12:56
@solnic Ok, got it. But my_gem/boot lives in system/ and not in lib/
Piotr Solnica
@solnic
Oct 14 2017 12:56
gimme a sec
@splattael just move stuff to my_gem/lib/my_gem/*
this way they will be on the load path (since it's a gem)
Peter Leitzen
@splattael
Oct 14 2017 12:59
Oh ok, so it's OK to put Container into lib/?
(That was my initial question ;))
@solnic Thank you for your help! :+1:
Piotr Solnica
@solnic
Oct 14 2017 13:03
@splattael it doesn't matter where you put files, really
the only exception is boot dir, which must be accessible as Container.root.join("boot")
Peter Leitzen
@splattael
Oct 14 2017 13:04
:+1:
Peter Leitzen
@splattael
Oct 14 2017 13:19
@solnic How about tweaking the example apps and move {import,container}.rb into lib.
@solnic You are right. You can put files wherever you want. Maybe it's just me, but I like "obey" example apps and their structures.
The examples I saw had their Container in system/ which confused me a lot. :smile_cat:
Piotr Solnica
@solnic
Oct 14 2017 18:29
@splattael it's because that's how we organized our apps, it's not mandatory
you can also change names of dirs
ie we have config.system_dir = :umbrella for the app where other apps are mounted
Peter Leitzen
@splattael
Oct 14 2017 18:47
@solnic I am slowly grasping the concepts. There are very powerful! Thank you again for your time and patience 💚