pre_commit_sort/
meta.rs

1/// ref. <https://pre-commit.com/#meta-hooks>
2use crate::ConfigHook;
3
4#[serde_with::skip_serializing_none]
5#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, Ord, PartialEq, PartialOrd, Clone)]
6pub struct Meta {
7    repo: String,
8    hooks: Vec<ConfigHook>,
9}
10
11impl Meta {
12    #[must_use]
13    pub fn new() -> Self {
14        Self {
15            repo: String::from("meta"),
16            hooks: Vec::new(),
17        }
18    }
19
20    pub fn add_hook(&mut self, hook: ConfigHook) {
21        self.hooks.push(hook);
22    }
23
24    pub fn sort(&mut self) {
25        self.hooks.sort();
26        self.hooks.dedup();
27    }
28}
29
30impl Default for Meta {
31    fn default() -> Self {
32        Self::new()
33    }
34}