Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/annotate_rb/model_annotator/model_files_getter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def call(options)
end
end

if options[:ignore_filename_regexp]
regexp = Regexp.new(options[:ignore_filename_regexp])
model_files.reject! { |_, file| File.basename(file).match?(regexp) }
end

if model_files.empty?
warn "No models found in directory '#{options[:model_dir].join("', '")}'."
warn "Either specify models on the command line, or use the --model-dir option."
Expand Down
1 change: 1 addition & 0 deletions lib/annotate_rb/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def from(options = {}, state = {})

PATH_OPTIONS = {
additional_file_patterns: [], # ModelAnnotator
ignore_filename_regexp: nil, # ModelAnnotator
model_dir: ["app/models"], # ModelAnnotator
require: [], # Core
root_dir: [""] # Core; Old model Annotate code depends on it being empty when not provided another value
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/annotate_rb/model_annotator/model_files_getter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@
is_expected.to contain_exactly([model_dir, "foo.rb"])
end
end

context "when `ignore_file_regexp` option is enabled" do
let(:base_options) { {model_dir: [model_dir], ignore_filename_regexp: '\Aquux\.rb\z'} }
let(:options) { AnnotateRb::Options.new(base_options, {working_args: []}) }

it "returns model files that do not match the regexp" do
is_expected.to contain_exactly(
[model_dir, "foo.rb"],
[model_dir, File.join("bar", "baz.rb")],
)
end
end
end

context "when the model files are specified" do
Expand Down
Loading