bctx_conductor/beacon/
local.rs1use super::{Beacon, BeaconEmitter};
2use std::path::PathBuf;
3
4pub struct LocalBeacon {
5 pub dir: PathBuf,
6}
7
8impl LocalBeacon {
9 pub fn new(dir: PathBuf) -> Self {
10 Self { dir }
11 }
12 pub fn default_path() -> PathBuf {
13 let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
14 PathBuf::from(home).join(".bctx").join("beacons")
15 }
16}
17
18impl BeaconEmitter for LocalBeacon {
19 fn emit(&self, beacon: &Beacon) {
20 let _ = std::fs::create_dir_all(&self.dir);
21 let name = format!("{}.json", beacon.timestamp.format("%Y%m%d_%H%M%S%f"));
22 let _ = std::fs::write(
23 self.dir.join(name),
24 serde_json::to_string(beacon).unwrap_or_default(),
25 );
26 }
27}