Enhance `--model-dir` to support glob patterns
This PR enhances the --model-dir option in the models command to support glob patterns, providing more flexibility in specifying model directories.
Problem:
Currently, the --model-dir option only accepts a comma-separated list of explicit directory paths. This can be cumbersome in projects with complex or non-standard directory structures, such as Packwerk-style modular monoliths or other setups using multiple directories under an apps/ or components/ folder. Users cannot easily target multiple model directories scattered across different components using wildcard patterns without listing each one individually.
Solution:
This PR modifies the AnnotateRb::ModelAnnotator::ModelFilesGetter class to:
- Treat each entry provided to
--model-diras a potential glob pattern. - Use
Dir.globto find all directories matching the provided patterns. - Search for
.rbfiles within each of the matched directories (respecting the--ignore-model-subdirectsoption).
This allows users to specify directories like components/*/app/models or apps/**/models to include models from various locations within the project structure, significantly simplifying configuration for modular applications.
Changes Included:
- Updated
lib/annotate_rb/model_annotator/model_files_getter.rbto implement glob pattern handling. - Added new RSpec tests in
spec/lib/annotate_rb/model_annotator/model_files_getter_spec.rbspecifically covering various glob pattern scenarios (simple star, recursive glob, combination with regular paths, interaction with--ignore-model-subdirects, handling non-matching patterns, and interaction with specified file arguments). - Updated existing RSpec tests to ensure compatibility and correct error handling for invalid/non-existent paths.
- Updated
README.mdto document the new glob pattern support for the--model-diroption.
Testing:
All existing and newly added RSpec tests for ModelFilesGetter pass, ensuring the new functionality works as expected and does not break existing behavior.
OMG... I worked on the same task without knowing there was a PR #198 😂
@ether-moon I just merged in #198, and will by deploying a new version soon. Please test it and let me know if this needs to be reviewed after
@ether-moon Sorry that this ended up being duplicate work. I'm going to close this for now, but feel free to re-open if it still hasn't been addressed.