Created
May 8, 2024 03:30
-
-
Save andria-dev/fde8a9e14a155ad24f19adbbcffe89f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anyhow::bail; | |
pub struct Recipe { | |
template: String, | |
} | |
impl Recipe { | |
const VARIABLES: [&'static str; 4] = ["URL", "SHA", "VERSION", "NEW_CHECK"]; | |
pub fn new(template: String) -> Self { | |
Recipe { template } | |
} | |
pub fn validate_listed(&self) -> anyhow::Result<()> { | |
let missing_variables = Recipe::VARIABLES | |
.iter() | |
.filter(|&variable| !self.template.contains(variable)) | |
.copied() | |
.collect::<Vec<_>>() | |
.join(", "); | |
if missing_variables.len() > 0 { | |
bail!("Missing variables: {}.", missing_variables) | |
} | |
Ok(()) | |
} | |
pub fn validate_immediate(&self) -> anyhow::Result<()> { | |
for variable in Recipe::VARIABLES { | |
if !self.template.contains(variable) { | |
bail!("Missing variable {}.", variable) | |
} | |
} | |
Ok(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment