1use crate::domain::CodeFact;
2use std::path::{Path, PathBuf};
3
4#[derive(Debug, Default)]
8pub struct ProjectContext {
9 pub root: PathBuf,
10 pub rust_files: Vec<PathBuf>,
11 pub markdown_files: Vec<PathBuf>,
12 pub yaml_files: Vec<PathBuf>,
13 pub makefile_files: Vec<PathBuf>,
14 pub code_facts: Vec<CodeFact>,
15}
16
17impl ProjectContext {
18 pub fn new(root: impl Into<PathBuf>) -> Self {
19 Self {
20 root: root.into(),
21 ..Self::default()
22 }
23 }
24
25 pub fn facts_named<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a CodeFact> + 'a {
26 self.code_facts.iter().filter(move |f| f.name == name)
27 }
28
29 pub fn rel<'a>(&self, path: &'a Path) -> &'a Path {
30 path.strip_prefix(&self.root).unwrap_or(path)
31 }
32}