aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/archiver
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-17 11:52:08 +0900
committernsfisis <nsfisis@gmail.com>2026-05-17 11:52:20 +0900
commit93a7671c98a9f022d757781f8fe583a2d55df07b (patch)
tree66ad0cef7ac58823262280a6bf94961c1d73f92a /crates/shirabe/src/package/archiver
parent35690acf83fa4473311a18e970ecd8156e1e6ac0 (diff)
downloadphp-shirabe-93a7671c98a9f022d757781f8fe583a2d55df07b.tar.gz
php-shirabe-93a7671c98a9f022d757781f8fe583a2d55df07b.tar.zst
php-shirabe-93a7671c98a9f022d757781f8fe583a2d55df07b.zip
refactor(shirabe): convert PHP abstract classes to Rust traits
PHP abstract classes are represented as traits to better align with Rust's type system.
Diffstat (limited to 'crates/shirabe/src/package/archiver')
-rw-r--r--crates/shirabe/src/package/archiver/base_exclude_filter.rs43
1 files changed, 22 insertions, 21 deletions
diff --git a/crates/shirabe/src/package/archiver/base_exclude_filter.rs b/crates/shirabe/src/package/archiver/base_exclude_filter.rs
index f20af20..6522d79 100644
--- a/crates/shirabe/src/package/archiver/base_exclude_filter.rs
+++ b/crates/shirabe/src/package/archiver/base_exclude_filter.rs
@@ -3,22 +3,16 @@
use shirabe_external_packages::composer::pcre::preg::Preg;
use shirabe_external_packages::symfony::component::finder::glob::Glob;
-#[derive(Debug)]
-pub struct BaseExcludeFilter {
- pub(crate) source_path: String,
- pub(crate) exclude_patterns: Vec<(String, bool, bool)>,
-}
-
-impl BaseExcludeFilter {
- pub fn new(source_path: String) -> Self {
- Self {
- source_path,
- exclude_patterns: vec![],
- }
- }
+pub trait BaseExcludeFilter {
+ fn source_path(&self) -> &str;
+ fn exclude_patterns(&self) -> &[(String, bool, bool)];
+ fn exclude_patterns_mut(&mut self) -> &mut Vec<(String, bool, bool)>;
- pub fn filter(&self, relative_path: &str, mut exclude: bool) -> bool {
- for (pattern, negate, strip_leading_slash) in &self.exclude_patterns {
+ /// Checks the given path against all exclude patterns in this filter
+ ///
+ /// Negated patterns overwrite exclude decisions of previous filters.
+ fn filter(&self, relative_path: &str, mut exclude: bool) -> bool {
+ for (pattern, negate, strip_leading_slash) in self.exclude_patterns() {
let path = if *strip_leading_slash {
&relative_path[1..]
} else {
@@ -36,30 +30,33 @@ impl BaseExcludeFilter {
exclude
}
- pub fn parse_lines<F>(&self, lines: Vec<String>, line_parser: F) -> Vec<(String, bool, bool)>
+ /// Processes a file containing exclude rules of different formats per line
+ fn parse_lines<F>(&self, lines: Vec<String>, line_parser: F) -> Vec<(String, bool, bool)>
where
F: Fn(&str) -> Option<(String, bool, bool)>,
{
lines
.into_iter()
.filter_map(|line| {
- let line = line.trim();
+ let line = line.trim().to_string();
if line.is_empty() || line.starts_with('#') {
return None;
}
- line_parser(line)
+ line_parser(&line)
})
.collect()
}
- pub fn generate_patterns(&self, rules: Vec<String>) -> Vec<(String, bool, bool)> {
+ /// Generates a set of exclude patterns for filter() from gitignore rules
+ fn generate_patterns(&self, rules: Vec<String>) -> Vec<(String, bool, bool)> {
rules
.into_iter()
.map(|rule| self.generate_pattern(&rule))
.collect()
}
- pub fn generate_pattern(&self, rule: &str) -> (String, bool, bool) {
+ /// Generates an exclude pattern for filter() from a gitignore rule
+ fn generate_pattern(&self, rule: &str) -> (String, bool, bool) {
let mut negate = false;
let mut pattern = String::new();
@@ -82,6 +79,10 @@ impl BaseExcludeFilter {
let glob_regex = Glob::to_regex(rule);
let rule_regex = &glob_regex[2..glob_regex.len() - 2];
- (format!("{}{}(?=$|/)", pattern, rule_regex), negate, false)
+ (
+ format!("{{{}{}(?=$|/)}}", pattern, rule_regex),
+ negate,
+ false,
+ )
}
}