♻️ refactor(config): rename EolCmd to EolAction for clarity
- rename `command` field in `EolRule` to `action` - update `set_command` method to use `EolAction` enum - adjust display formatting to reflect the change to "action"
This commit is contained in:
committed by
Jeremiah Russell
parent
68b6cba9c1
commit
5096fd2b19
@@ -2,7 +2,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{Retention, eol_cmd::EolCmd};
|
use crate::{Retention, eol_cmd::EolAction};
|
||||||
|
|
||||||
/// End of life rules
|
/// End of life rules
|
||||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||||
@@ -11,7 +11,7 @@ pub(crate) struct EolRule {
|
|||||||
retention: String,
|
retention: String,
|
||||||
labels: Vec<String>,
|
labels: Vec<String>,
|
||||||
query: Option<String>,
|
query: Option<String>,
|
||||||
command: String,
|
action: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for EolRule {
|
impl fmt::Display for EolRule {
|
||||||
@@ -31,9 +31,16 @@ impl fmt::Display for EolRule {
|
|||||||
if count > 1 {
|
if count > 1 {
|
||||||
period.push('s');
|
period.push('s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let action = match self.action.to_lowercase().as_str() {
|
||||||
|
"trash" => "moves the message to trash",
|
||||||
|
"delete" => "deletes the message",
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"Rule #{} is active on {} and applies when the message is {count} {period} old.",
|
"Rule #{} is active on {} and {action} is {count} {period} old.",
|
||||||
self.id,
|
self.id,
|
||||||
self.labels.join(", ")
|
self.labels.join(", ")
|
||||||
)
|
)
|
||||||
@@ -47,7 +54,7 @@ impl EolRule {
|
|||||||
pub(crate) fn new(id: usize) -> Self {
|
pub(crate) fn new(id: usize) -> Self {
|
||||||
EolRule {
|
EolRule {
|
||||||
id,
|
id,
|
||||||
command: EolCmd::Trash.to_string(),
|
action: EolAction::Trash.to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,6 +83,11 @@ impl EolRule {
|
|||||||
pub(crate) fn labels(&self) -> &Vec<String> {
|
pub(crate) fn labels(&self) -> &Vec<String> {
|
||||||
&self.labels
|
&self.labels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_command(&mut self, value: EolAction) -> &mut Self {
|
||||||
|
self.action = value.to_string();
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user