weavatrix_scan/config/
ignore_policy.rs1use std::path::PathBuf;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
9#[allow(clippy::struct_excessive_bools)]
10pub struct IgnorePolicy {
11 pub parent_rules: bool,
12 pub git_ignore: bool,
13 pub dot_ignore: bool,
14 pub custom_ignore: bool,
15 pub git_exclude: bool,
16 pub git_global: bool,
17 pub require_git: bool,
19 pub explicit_files: Vec<PathBuf>,
20}
21
22impl Default for IgnorePolicy {
23 fn default() -> Self {
24 Self::repository()
25 }
26}
27
28impl IgnorePolicy {
29 #[must_use]
30 pub const fn repository() -> Self {
31 Self {
32 parent_rules: false,
33 git_ignore: true,
34 dot_ignore: true,
35 custom_ignore: true,
36 git_exclude: false,
37 git_global: false,
38 require_git: false,
39 explicit_files: Vec::new(),
40 }
41 }
42
43 #[must_use]
44 pub const fn git_compatible() -> Self {
45 Self {
46 parent_rules: true,
47 git_ignore: true,
48 dot_ignore: true,
49 custom_ignore: true,
50 git_exclude: true,
51 git_global: true,
52 require_git: true,
53 explicit_files: Vec::new(),
54 }
55 }
56
57 #[must_use]
58 pub const fn with_parent_rules(mut self, enabled: bool) -> Self {
59 self.parent_rules = enabled;
60 self
61 }
62
63 #[must_use]
64 pub const fn with_git_ignore(mut self, enabled: bool) -> Self {
65 self.git_ignore = enabled;
66 self
67 }
68
69 #[must_use]
70 pub const fn with_dot_ignore(mut self, enabled: bool) -> Self {
71 self.dot_ignore = enabled;
72 self
73 }
74
75 #[must_use]
76 pub const fn with_custom_ignore(mut self, enabled: bool) -> Self {
77 self.custom_ignore = enabled;
78 self
79 }
80
81 #[must_use]
82 pub const fn with_git_exclude(mut self, enabled: bool) -> Self {
83 self.git_exclude = enabled;
84 self
85 }
86
87 #[must_use]
88 pub const fn with_git_global(mut self, enabled: bool) -> Self {
89 self.git_global = enabled;
90 self
91 }
92
93 #[must_use]
94 pub const fn with_require_git(mut self, enabled: bool) -> Self {
95 self.require_git = enabled;
96 self
97 }
98
99 #[must_use]
100 pub fn with_explicit_file(mut self, path: impl Into<PathBuf>) -> Self {
101 self.explicit_files.push(path.into());
102 self
103 }
104}