Confusion over `require` when booting a dependency

Hi there, I’m new here and new to dry-rb. I’m reading through the docs on dry-system and trying to follow the examples, but I’ve run into some confusion around requiring third-party code as a bootable dependency.

The example:

# system/boot/logger.rb
Application.boot(:logger) do
  init do
    require 'logger'
  end

  start do
    register(:logger, Logger.new($stdout))
  end
end

Copying this example, it doesn’t seem to matter whether I require "logger" or not. The logger is registered and works either way. Maybe that’s just because logger is part of the ruby standard lib. However, when I try to do something similar with a gem from my Gemfile, like so:

App.boot(:curses) do
  init do
    require "curses"
  end

  start do
    # ...
  end
end

I get a require': cannot load such file -- curses (LoadError) error. This happens with any gem from my Gemfile that I try to require, not just this one. If i require outside of the App.boot block, there isn’t any problem. I have also tried ::Kernel.require and get the same thing.

Am I misunderstanding what require in the init block is actually for?

Hey Will, welcome :smile:

If it works w/o the require statement then something else must be requiring it. It is always require-able because, like you mentioned, it’s bundled with ruby in the stdlib.

My guess is that you didn’t do require "bundler/setup" before booting starts, so the LOAD_PATH is not set for the gems from your Gemfile.

Thank you so much @solnic!

I had suspected this was related to my lack of understanding around bundler. I should have dug in a little more there before I posted here. require "bundler/setup" was exactly what I needed.

@gotno no worries :slight_smile: I’m glad that it worked for you.