Dry-rb System start

Howdy all, I have been trying to get started with setting up my application with dry-system and I am also reading through some other code bases and the book Ruby on Roda. I am trying to work through the docs but am having a hard time getting things tied together.

A couple of questions to start:
Are the docs updated to represent the API as is?

Is there documentation on the available plugins?

Are there some eli5 walkthroughs or anything? I am down to write some blogs on the process, I am just having a hard time wrapping my head around the library.

I have found that some projects I have seen use older versions of dry-system.

I have now been trying to configure Zeitwerk in the configure block. I have seen references to a plugin, but I haven’t seen approachable documentation.

Does the plugin enable reloading by default, or should I use something like the listen gem to enable automatic reloading?

# frozen_string_literal: true

require 'bundler/setup'
require 'dry-system'
require 'zeitwerk'

# configurations for the application
class Application < Dry::System::Container
  use :env, inferrer: -> { ENV.fetch('RACK_ENV', 'development') }

  configure do |_config|
    loader = Zeitwerk::Loader.new
    loader.enable_reloading if env == 'development'
    loader.push_dir('allocs')
    loader.ignore('allocs/*/routes.rb')
    loader.setup
    loader.eager_load if env == 'production'
  end
end

I attempted to extract the loader into its own provider:

# frozen_string_literal: true

# This file contains logger configuration.

Application.register_provider(:loader) do
  prepare do
    require 'zeitwerk'
  end
  start do
    target.start :environment_variables
    loader = Zeitwerk::Loader.new
    loader.enable_reloading if target[:env] == 'development'
    loader.push_dir('allocs')
    # loader.collapse('#{__dir__}/*/views/*')
    loader.ignore('allocs/*/routes.rb')
    loader.setup
    loader.eager_load if target[:env] == 'production'
    register(:loader, loader)
  end
end

And then in the config.ru I attempted to get code reloading with the listen gem.

loader = Application.resolve(:loader)
Listen.to(__dir__, only: /\.rb$/, force_polling: true) { loader.reload }.start

run lambda { |env|
  loader.reload
  App.call(env)
}

Attempt #544 did not work out :face_holding_back_tears:

It’s not a huge help, but the examples here: dry-system/examples at main · dry-rb/dry-system · GitHub show how to set up a couple of different applications including one using zeitwerk.

1 Like

I appreciate the pointer. I’ve seen those and unfortunately, they are not much help. They show configuring Zeitwerk with a system adapter, but I have a more complicated ask that might require the full features including collapsing, glob ignoring, etc.

In my example above the provider does load the application, I just need to figure out how to appropriately reload the code with a Roda application.