Skip to content

Commit

Permalink
✨ Add a new matcher type resource-name-regexp
Browse files Browse the repository at this point in the history
See also: #13
  • Loading branch information
ShellWen committed Nov 28, 2023
1 parent 6edd3d4 commit 46d451f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/core/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ pub(crate) trait SourceMatcher {
pub(crate) enum SourceMatcherEnum {
#[serde(rename = "resource-name-keyword")]
ResourceNameKeywordMatcher(ResourceNameKeywordMatcher),
#[serde(rename = "resource-name-regexp")]
ResourceNameRegexpMatcher(ResourceNameRegexpMatcher),
}

impl SourceMatcher for SourceMatcherEnum {
fn matches(&self, source: &Source) -> bool {
match self {
SourceMatcherEnum::ResourceNameKeywordMatcher(matcher) => matcher.matches(source),
SourceMatcherEnum::ResourceNameRegexpMatcher(matcher) => matcher.matches(source),
}
}
}
Expand All @@ -31,3 +34,15 @@ impl SourceMatcher for ResourceNameKeywordMatcher {
source.resource_name.contains(&self.keyword)
}
}

#[derive(Deserialize, Debug)]
pub struct ResourceNameRegexpMatcher {
pub regexp: String,
}

impl SourceMatcher for ResourceNameRegexpMatcher {
fn matches(&self, source: &Source) -> bool {
let re = regex::Regex::new(&self.regexp).unwrap();
re.is_match(&source.resource_name)
}
}

0 comments on commit 46d451f

Please sign in to comment.