use std::cell::RefCell;
use crate::domain::error::Result;
use crate::domain::repo::Repo;
use crate::storage::repository::RepoRepository;
pub struct InMemoryRepoRepository {
repos: RefCell<Vec<Repo>>,
sections: RefCell<Vec<String>>,
}
impl InMemoryRepoRepository {
pub fn new(initial: Vec<Repo>) -> Self {
InMemoryRepoRepository {
repos: RefCell::new(initial),
sections: RefCell::new(Vec::new()),
}
}
}
impl RepoRepository for InMemoryRepoRepository {
fn find_all(&self) -> Result<Vec<Repo>> {
Ok(self.repos.borrow().clone())
}
fn save_all(&self, repos: &[Repo]) -> Result<()> {
*self.repos.borrow_mut() = repos.to_vec();
Ok(())
}
fn find_sections(&self) -> Result<Vec<String>> {
Ok(self.sections.borrow().clone())
}
fn save_sections(&self, sections: &[String]) -> Result<()> {
*self.sections.borrow_mut() = sections.to_vec();
Ok(())
}
}