Add filter: Version{Gt, Lt}

This commit is contained in:
Matthias Beyer 2016-03-15 23:13:59 +01:00
parent d75595e4d8
commit 21013dd76f
3 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,46 @@
use semver::Version;
use toml::Value;
use libimagstore::store::Entry;
use builtin::header::field_path::FieldPath;
use filter::Filter;
pub struct VersionGt {
version: Version,
}
impl VersionGt {
pub fn new(version: Version) -> VersionGt {
VersionGt { version: version }
}
}
impl Filter for VersionGt {
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,45 @@
use semver::Version;
use toml::Value;
use libimagstore::store::Entry;
use builtin::header::field_path::FieldPath;
use filter::Filter;
pub struct VersionLt {
version: Version,
}
impl VersionLt {
pub fn new(version: Version) -> VersionLt {
VersionLt { version: version }
}
}
impl Filter for VersionLt {
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

@ -1 +1,3 @@
pub mod eq; pub mod eq;
pub mod lt;
pub mod gt;