Enhance --model-dir
to support glob patterns
#213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enhances the
--model-dir
option in themodels
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 anapps/
orcomponents/
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:--model-dir
as a potential glob pattern.Dir.glob
to find all directories matching the provided patterns..rb
files within each of the matched directories (respecting the--ignore-model-subdirects
option).This allows users to specify directories like
components/*/app/models
orapps/**/models
to include models from various locations within the project structure, significantly simplifying configuration for modular applications.Changes Included:
lib/annotate_rb/model_annotator/model_files_getter.rb
to implement glob pattern handling.spec/lib/annotate_rb/model_annotator/model_files_getter_spec.rb
specifically 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).README.md
to document the new glob pattern support for the--model-dir
option.Testing:
All existing and newly added RSpec tests for
ModelFilesGetter
pass, ensuring the new functionality works as expected and does not break existing behavior.