Add filter: Version{Gt, Lt}
This commit is contained in:
parent
d75595e4d8
commit
21013dd76f
3 changed files with 93 additions and 0 deletions
46
libimagentryfilter/src/builtin/header/version/gt.rs
Normal file
46
libimagentryfilter/src/builtin/header/version/gt.rs
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
45
libimagentryfilter/src/builtin/header/version/lt.rs
Normal file
45
libimagentryfilter/src/builtin/header/version/lt.rs
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1 +1,3 @@
|
|||
pub mod eq;
|
||||
pub mod lt;
|
||||
pub mod gt;
|
||||
|
|
Loading…
Reference in a new issue