Merge pull request #256 from matthiasbeyer/libimagentryfilter/version-filter
Libimagentryfilter/version filter
This commit is contained in:
commit
afee9152ed
8 changed files with 192 additions and 0 deletions
|
@ -9,6 +9,7 @@ itertools = "0.4.7"
|
|||
log = "0.3.4"
|
||||
regex = "0.1.48"
|
||||
toml = "0.1.27"
|
||||
semver = "0.2.1"
|
||||
|
||||
[dependencies.libimagstore]
|
||||
path = "../libimagstore"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
4
libimagentryfilter/src/builtin/header/version/mod.rs
Normal file
4
libimagentryfilter/src/builtin/header/version/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
pub mod eq;
|
||||
pub mod gt;
|
||||
pub mod lt;
|
||||
pub mod range;
|
50
libimagentryfilter/src/builtin/header/version/range.rs
Normal file
50
libimagentryfilter/src/builtin/header/version/range.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use semver::Version;
|
||||
|
||||
use libimagstore::store::Entry;
|
||||
|
||||
use builtin::header::version::gt::VersionGt;
|
||||
use builtin::header::version::lt::VersionLt;
|
||||
use filter::Filter;
|
||||
use ops::and::And;
|
||||
use ops::not::Not;
|
||||
|
||||
pub struct VersionInRange {
|
||||
and: And,
|
||||
}
|
||||
|
||||
impl VersionInRange {
|
||||
|
||||
pub fn new(lowerbound: Version, upperbound: Version) -> VersionInRange {
|
||||
VersionInRange { and: VersionGt::new(lowerbound).and(Box::new(VersionLt::new(upperbound))) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Filter for VersionInRange {
|
||||
|
||||
fn filter(&self, e: &Entry) -> bool {
|
||||
self.and.filter(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct VersionOutOfRange {
|
||||
not: Not
|
||||
}
|
||||
|
||||
impl VersionOutOfRange {
|
||||
|
||||
pub fn new(lowerbound: Version, upperbound: Version) -> VersionOutOfRange {
|
||||
VersionOutOfRange { not: VersionInRange::new(lowerbound, upperbound).not() }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Filter for VersionOutOfRange {
|
||||
|
||||
fn filter(&self, e: &Entry) -> bool {
|
||||
self.not.filter(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
extern crate itertools;
|
||||
extern crate regex;
|
||||
extern crate toml;
|
||||
extern crate semver;
|
||||
|
||||
extern crate libimagstore;
|
||||
extern crate libimagtag;
|
||||
|
|
Loading…
Reference in a new issue