refactor: CheckFreshness and DiffDiagram take &str instead of &Path
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
use archlens_domain::{DomainError, NormalizedGraph, ports::DiagramRenderer};
|
||||
|
||||
/// Compares the current rendered output against an on-disk file.
|
||||
/// Compares the current rendered output against provided file content.
|
||||
/// Returns `Ok(true)` if up to date, `Ok(false)` if stale.
|
||||
pub struct CheckFreshness<'a> {
|
||||
pub graph: &'a NormalizedGraph,
|
||||
pub renderer: &'a dyn DiagramRenderer,
|
||||
pub existing_path: &'a std::path::Path,
|
||||
pub existing_content: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> CheckFreshness<'a> {
|
||||
pub fn execute(&self) -> Result<bool, DomainError> {
|
||||
let rendered = self.renderer.render(self.graph.as_graph())?;
|
||||
let current = rendered.files().first().map(|f| f.content()).unwrap_or("");
|
||||
let existing = std::fs::read_to_string(self.existing_path).unwrap_or_default();
|
||||
Ok(current == existing)
|
||||
Ok(current == self.existing_content)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,22 +12,21 @@ impl DiffResult {
|
||||
}
|
||||
}
|
||||
|
||||
/// Compares the rendered current graph against an existing diagram file and
|
||||
/// Compares the rendered current graph against provided diagram content and
|
||||
/// returns which lines were added or removed.
|
||||
pub struct DiffDiagram<'a> {
|
||||
pub graph: &'a NormalizedGraph,
|
||||
pub renderer: &'a dyn DiagramRenderer,
|
||||
pub existing_path: &'a std::path::Path,
|
||||
pub existing_content: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> DiffDiagram<'a> {
|
||||
pub fn execute(&self) -> Result<DiffResult, DomainError> {
|
||||
let rendered = self.renderer.render(self.graph.as_graph())?;
|
||||
let current = rendered.files().first().map(|f| f.content()).unwrap_or("");
|
||||
let existing = std::fs::read_to_string(self.existing_path).unwrap_or_default();
|
||||
|
||||
let current_lines: std::collections::HashSet<&str> = current.lines().collect();
|
||||
let existing_lines: std::collections::HashSet<&str> = existing.lines().collect();
|
||||
let existing_lines: std::collections::HashSet<&str> = self.existing_content.lines().collect();
|
||||
|
||||
let added: Vec<String> = current_lines
|
||||
.difference(&existing_lines)
|
||||
|
||||
Reference in New Issue
Block a user