Skip to content

Commit c748ae1

Browse files
authored
[github] Add HttpCache::in_dir constructor to allow for custom cache placement (#59)
* Add HttpCache::in_dir constructor to allow for custom cache placement Before only the home dir could be used, this makes it a bit more ergonomic if the user has other desires * Use HttpCache::in_dir for HttpCache::in_home_dir
1 parent b56d1be commit c748ae1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

github/src/http_cache.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ impl dyn HttpCache {
3535
}
3636

3737
pub fn in_home_dir() -> BoxedHttpCache {
38-
let mut dir = dirs::home_dir().expect("Expected a home dir");
39-
dir.push(".github/cache");
40-
Box::new(FileBasedCache::new(dir))
38+
Self::in_dir(&dirs::home_dir().expect("Expected a home dir"))
39+
}
40+
41+
pub fn in_dir(path: &Path) -> BoxedHttpCache {
42+
if path.is_dir() {
43+
let mut path = path.to_owned();
44+
path.push(".github/cache");
45+
Box::new(FileBasedCache::new(path))
46+
} else {
47+
panic!("Expected a dir");
48+
}
4149
}
4250
}
4351

0 commit comments

Comments
 (0)