-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::{transformer::TransformContext, TransformResult, Transformer}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Just outputs a fixed string (plain text). | ||
/// | ||
/// # Example: | ||
/// | ||
/// #... | ||
/// rules: | ||
/// field_name: | ||
/// plain: "some text" | ||
/// ``` | ||
#[derive(Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Debug)] | ||
pub struct PlainTransformer(String); | ||
|
||
impl Transformer for PlainTransformer { | ||
fn transform( | ||
&self, | ||
_field_name: &str, | ||
_field_value: &str, | ||
_ctx: &Option<TransformContext>, | ||
) -> TransformResult { | ||
Ok(Some(self.0.clone())) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::Transformers; | ||
|
||
#[test] | ||
fn parse_and_transform() { | ||
let cfg = "plain: 'some text'"; | ||
let transformer: Transformers = serde_yaml::from_str(cfg).unwrap(); | ||
let result = transformer.transform("field", "", &None).unwrap().unwrap(); | ||
|
||
assert_eq!(result, "some text"); | ||
} | ||
} |
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