annotaterb
annotaterb copied to clipboard
Feature request: packs-rails support
I'm trying out annotaterb on a Rails project which has packs-rails setup. The packs/ directory doesn't get automatically picked up, understandably.
- I tried to use
:root_dir: ['.', 'packs/*']and onlyapp/directory in the root gets picked up, none of the packs were recognized.- I also tried variations of
packs/*by expanding it topacks/packonepacks/packtwoetc, still doesn't work.
- I also tried variations of
- 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
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.
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!
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(",") %>