use std::path::{Path, PathBuf};
#[derive(Debug)]
pub struct Memory {
path: PathBuf,
}
impl Memory {
pub fn for_wave(repo_root: &Path, wave: &str) -> Self {
Self {
path: repo_root.join("wave").join(wave).join("MEMORY.md"),
}
}
pub fn path(&self) -> &Path {
&self.path
}
pub fn read(&self) -> String {
std::fs::read_to_string(&self.path).unwrap_or_default()
}
pub fn write(&self, content: &str) -> std::io::Result<()> {
if let Some(parent) = self.path.parent() {
std::fs::create_dir_all(parent)?;
}
std::fs::write(&self.path, content)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn read_missing_file_is_empty() {
let tmp = tempfile::tempdir().expect("tempdir");
let memory = Memory::for_wave(tmp.path(), "ghost");
assert_eq!(memory.read(), "");
}
}