Exclude file pattern match

closes #61
This commit is contained in:
Vitalii Elenhaupt 2018-05-29 13:19:00 +03:00
parent c12b4f1aa5
commit e1b51f62a5
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
4 changed files with 21 additions and 4 deletions

View file

@ -55,10 +55,10 @@ module Ameba::Rule
rule.excluded?(Source.new "", "source.cr").should be_true
end
pending "returns true if source matches the wildcard" do
it "returns true if source matches the wildcard" do
rule = DummyRule.new
rule.excluded = %w(**/*.cr)
rule.excluded?(Source.new "", "source.cr").should be_true
rule.excluded?(Source.new "", __FILE__).should be_true
end
it "returns false if source does not match the wildcard" do

View file

@ -35,5 +35,17 @@ module Ameba
s.fullpath.should_not be_nil
end
end
describe "#matches_path?" do
it "returns true if source's path is matched" do
s = Source.new "", "source.cr"
s.matches_path?("source.cr").should be_true
end
it "returns false if source's path is not matched" do
s = Source.new "", "source.cr"
s.matches_path?("new_source.cr").should be_false
end
end
end
end

View file

@ -75,8 +75,8 @@ module Ameba::Rule
#
def excluded?(source)
excluded.try &.any? do |path|
# TODO: file pattern match
source.path == path || source.fullpath == File.expand_path(path)
source.matches_path?(path) ||
Dir.glob(path).any? { |glob| source.matches_path? glob }
end
end

View file

@ -111,5 +111,10 @@ module Ameba
def fullpath
@fullpath ||= File.expand_path @path
end
# Returns true if *filepath* matches the source's path, false if it does not.
def matches_path?(filepath)
path == filepath || path == File.expand_path(filepath)
end
end
end