Sha256: 59a375795143cff03a988860929ef6a7c7dbc175d750218d98e8f4147a2d4de3

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "dry/system"

module Dry
  module Rails
    module AutoRegistrars
      # This is the default auto-registrar configured in the Container
      #
      # @api private
      class App < System::AutoRegistrar
        # Resolve a path relative to the system root
        #
        # This works just like in `dry-system` except that it's app-dir aware. This means it will
        # turn `app/operations/foo/bar` to `foo/bar` because app dirs are treated as root dirs.
        #
        # In a typical dry-system setup `app` would be the root and everything inside this path
        # would indicate the constant hierachy, so `app/operations/foo/bar` => `Operations/Foo/Bar`
        # but *this is not the Rails convention* so we need this special auto-registrar.
        #
        # @api private
        def relative_path(dir, file_path)
          path = super
          return path unless dir.start_with?("app")

          path.split("/")[1..-1].join("/")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-rails-0.7.0 lib/dry/rails/auto_registrars/app.rb
dry-rails-0.6.0 lib/dry/rails/auto_registrars/app.rb