# frozen_string_literal: true require "erb" require "zeitwerk" require "phlexing" require "dry/files" require "tqdm" def add_autoload_entries(module_file, resources) # rubocop:disable Style/TopLevelMethodDefinition autoload_content = resources.map do |resource| (" " * 6) + "autoload :#{resource.name}, \"#{resource.relative_file_path}\"" end lines = File.readlines(module_file) start = lines.index { |line| line.include?("# autogenerated:start") } finish = lines.index { |line| line.include?("# autogenerated:finish") } # Remove existing lines lines.slice!(start + 1..finish - 1) # Place new lines lines.insert(start + 1, "#{autoload_content.join("\n")}\n") File.write(module_file, lines.join) end