These are chat archives for dry-rb/chat

25th
Feb 2018
Jonah
@jonahx
Feb 25 2018 21:25

In the dry-system docs it says:

When components are auto-registered, default identifiers are created based on file paths, ie lib/api/client resolves to API::Client class with identifier api.client.

How is API determined to be all caps here? I would think it would be Api...

Or is it assuming that the Client class defined my the file lib/api/client is inside a module called API?
Gustavo Caso
@GustavoCaso
Feb 25 2018 21:40
it should be inside a module
or a class @jonahx
Gustavo Caso
@GustavoCaso
Feb 25 2018 21:47
you can look at the test suite inside the library to see some examples
Hope this helps
Jonah
@jonahx
Feb 25 2018 21:57
@GustavoCaso thanks
Jonah
@jonahx
Feb 25 2018 23:35

I’m having trouble getting dry-system to work, and I think I’m missing something obvious, but even after reading the docs and test cases I don’t know what it is. In system/container.rb I have:

require 'dry/system/container'

class Application < Dry::System::Container
  configure do |config|
    config.root = Pathname('.')
    config.auto_register = 'domain'
    config.auto_register = 'use_cases'
  end

  load_paths!('lib', 'use_cases')
end

Application.finalize!

p Application['bot_reply']

and in system.import.rb I have:

require 'system/container'
Import = Application.injector

In lib/bot_reply.rb I have:

require 'dry-struct'
require 'import'

class BotReply < Dry::Struct
# stuff
end

If I execute system/container.rb as a test, I get the error:

Nothing registered with the key "bot_reply" (Dry::Container::Error)

What am I missing?

Tim Riley
@timriley
Feb 25 2018 23:36
    config.auto_register = 'domain'
    config.auto_register = 'use_cases'
Those aren’t right if you’re expecting lib/bot_reply.rb to be registered
And you should only have one auto_register config (it can be an array)
try this:
config.auto_register = “lib”
then, after you’ve finalized your container, you can do Application.keys to see what it has
Jonah
@jonahx
Feb 25 2018 23:45
@timriley I’m still getting empty keys after making those changes and fixing the typo you caught (lib should have been domain):
require 'dry/system/container'

class Application < Dry::System::Container
  configure do |config|
    config.root = Pathname('.')
    config.auto_register = 'domain'
    # config.auto_register = 'use_cases'
  end

  load_paths!('domain')
end

Application.finalize!

p Application.keys # => []
Tim Riley
@timriley
Feb 25 2018 23:59
where is this application.rb file located?
And what does Application.config.root return?