use std::path::{Path, PathBuf};
pub struct FileHandler {
- pub strategies: Vec<Box<dyn FileHandlerStrategy>>,
+ pub strategies: Vec<Box<dyn Strategy>>,
pub layout: Option<String>,
}
impl FileHandler {
pub fn identify(&self, path: &Path) -> FileType {
- for strategy in self.strategies.iter() {
+ for strategy in &self.strategies {
if strategy.is(path) {
return strategy.identify();
}
gemini_destination: &Path,
files: &[File],
) {
- files.iter().for_each(|file| {
+ for file in files {
self.handle(source, html_destination, gemini_destination, file);
- });
+ }
}
pub fn handle(
}
}
-pub trait FileHandlerStrategy {
+pub trait Strategy {
fn is(&self, path: &Path) -> bool;
fn identify(&self) -> FileType;
fn can_handle(&self, file_type: &FileType) -> bool;
file_type: FileType,
}
- impl FileHandlerStrategy for MockStrategy {
+ impl Strategy for MockStrategy {
fn is(&self, _path: &Path) -> bool {
self.is_match
}
let handler = FileHandler {
strategies: vec![Box::new(mock_strategy)],
- layout: None,
+ layout: Some("None".to_string()),
};
let path = PathBuf::from("test.whatever");
+ let file = File{
+ path: path.clone(),
+ file_type: FileType::Gemini
+ };
assert!(matches!(handler.identify(&path), FileType::Gemini));
+ handler.handle(&path, &path, &path, &file);
}
#[test]