-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3434 from matthewbadeau/feature/ignore_files
Configure files / directories that should be ignored during scan
- Loading branch information
Showing
9 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,3 +171,5 @@ gem "pghero", "~> 3.6" | |
gem "pg_query", "~> 6.0" | ||
|
||
gem "get_process_mem", "~> 1.0" | ||
|
||
gem "to_regexp", "~> 0.2.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class RegexArrayValidator < ActiveModel::EachValidator | ||
def validate_each(record, attribute, value) | ||
return unless value.any? { |pattern| pattern.to_regexp.nil? } | ||
record.errors.add(attribute, :invalid) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h3><%= t(".title") %></h3> | ||
<p class='lead'> | ||
<%= t ".summary" %> | ||
</p> | ||
<div class="row mb-2"> | ||
<p> | ||
<%= t ".custom_ignore_filters.details" %> | ||
</p> | ||
<%= form.label nil, t(".custom_ignore_filters.label"), for: "files[model_ignored_files]", class: "col-sm-4 col-form-label" %> | ||
<div class="col-sm-8 form-check form-switch"> | ||
<%= form.text_area "files[model_ignored_files]", value: SiteSettings.model_ignored_files.join("\n").gsub(/^\[|\]$/, ""), class: "form-control" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe RegexArrayValidator do | ||
subject(:validator) { described_class.new({attributes: {any: true}}) } | ||
|
||
let(:errors) { ActiveModel::Errors.new(subject) } | ||
|
||
let(:record) { instance_double(ActiveModel::Validations, errors: errors) } | ||
|
||
let(:array_of_regexes) { | ||
%w[ | ||
/^\.[^\.]+/ | ||
/.*\/@eaDir\/.*/ | ||
/__MACOSX/ | ||
] | ||
} | ||
|
||
describe "#validate_each(record, attribute, value)" do | ||
it "adds error to invalid record when the array has an invalid regex" do | ||
array_of_regexes.push "INVALID_REGEX" | ||
expect { | ||
validator.validate_each(record, :model_ignore_files, array_of_regexes) | ||
}.to change(record.errors, :count) | ||
.and change { record.errors.first&.type }.to eq(:invalid) | ||
end | ||
|
||
it "does not add error to invalid record when array contains only regexes" do | ||
puts array_of_regexes.inspect | ||
expect { | ||
validator.validate_each(record, :model_ignore_files, array_of_regexes) | ||
}.not_to change(record.errors, :count) | ||
end | ||
end | ||
end |