Add VersionEq filter
This commit is contained in:
parent
0786094150
commit
d75595e4d8
3 changed files with 46 additions and 0 deletions
|
@ -7,3 +7,4 @@ pub mod field_istype;
|
|||
pub mod field_lt;
|
||||
pub mod field_path;
|
||||
pub mod field_predicate;
|
||||
pub mod version;
|
||||
|
|
44
libimagentryfilter/src/builtin/header/version/eq.rs
Normal file
44
libimagentryfilter/src/builtin/header/version/eq.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use semver::Version;
|
||||
use toml::Value;
|
||||
|
||||
use libimagstore::store::Entry;
|
||||
|
||||
use builtin::header::field_path::FieldPath;
|
||||
use filter::Filter;
|
||||
|
||||
pub struct VersionEq {
|
||||
version: Version,
|
||||
}
|
||||
|
||||
impl VersionEq {
|
||||
|
||||
pub fn new(version: Version) -> VersionEq {
|
||||
VersionEq { version: version }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Filter for VersionEq {
|
||||
|
||||
fn filter(&self, e: &Entry) -> bool {
|
||||
e.get_header()
|
||||
.read("imag.version")
|
||||
.map(|val| {
|
||||
val.map(|v| {
|
||||
match v {
|
||||
Value::String(s) => {
|
||||
match Version::parse(&s[..]) {
|
||||
Ok(v) => v == self.version,
|
||||
_ => false
|
||||
}
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
1
libimagentryfilter/src/builtin/header/version/mod.rs
Normal file
1
libimagentryfilter/src/builtin/header/version/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod eq;
|
Loading…
Reference in a new issue