annotaterb icon indicating copy to clipboard operation
annotaterb copied to clipboard

Feature request: packs-rails support

Open wilsonehusin opened this issue 1 year ago • 3 comments

I'm trying out annotaterb on a Rails project which has packs-rails setup. The packs/ directory doesn't get automatically picked up, understandably.

  1. I tried to use :root_dir: ['.', 'packs/*'] and only app/ directory in the root gets picked up, none of the packs were recognized.
    • I also tried variations of packs/* by expanding it to packs/packone packs/packtwo etc, still doesn't work.
  2. I tried to use `:model_dir: ['app/models', 'packs/*/app/models'] and still the packs aren't picked up. However, expanding the glob works!

While the title is specifically on packs-rails, I wouldn't mind having a compromise via :root_dir: or :model_dir: if it supports globs 😄

P.S. 👋🏻 hey Andrew, hope you've been well!

Versions

  • annotaterb 4.6.0
  • rails 6.1
  • ruby 3.1

wilsonehusin avatar Mar 26 '24 19:03 wilsonehusin

Hi Wilson, I'm doing alright, hope you're doing good as well. I haven't used pack-rails gem before so let me take a look into it. I think there's demand for supporting alternative structures as also seen in #82.

I'm hoping to dedicate some time soon to get a good understanding of the different use cases and a path forward.

drwl avatar Mar 28 '24 01:03 drwl

To unblock us we updated our rake task to look like this:

# This rake task was added by annotate_rb gem.

# Can set `ANNOTATERB_SKIP_ON_DB_TASKS` to be anything to skip this
if Rails.env.development? && ENV["ANNOTATERB_SKIP_ON_DB_TASKS"].nil?
  require "annotate_rb"
  require "yaml"

  config_file = ".annotaterb.yml"
  config = YAML.load_file(config_file)
  model_dirs = `find packs -type d -name 'app/models' -prune -o -path '*/app/models' -type d`.split("\n").sort
  config[:model_dir] = ["app/models"] + model_dirs
  File.open(config_file, "w") { |f| YAML.dump(config, f) }

  AnnotateRb::Core.load_rake_tasks
end

It would be nice to have support for this in annotaterb though!

gmcabrita avatar May 30 '24 10:05 gmcabrita

Having the config file be a ruby script had the advantage that we could more easily customize things like this. With annotate, we could do:

"model_dir" => Dir.glob("**/app/models").join(","),

An approach to get something similar in a yaml file could be to allow ERB syntax to be used in the file. So we could do:

model_dir: <%= Dir.glob("**/app/models").join(",") %>

jeromepl avatar Dec 10 '24 20:12 jeromepl