Add VersionEq filter

This commit is contained in:
Matthias Beyer 2016-03-15 23:11:30 +01:00
parent 0786094150
commit d75595e4d8
3 changed files with 46 additions and 0 deletions

View file

@ -7,3 +7,4 @@ pub mod field_istype;
pub mod field_lt;
pub mod field_path;
pub mod field_predicate;
pub mod version;

View 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)
}
}

View file

@ -0,0 +1 @@
pub mod eq;