Merge pull request #256 from matthiasbeyer/libimagentryfilter/version-filter

Libimagentryfilter/version filter
This commit is contained in:
Matthias Beyer 2016-03-19 15:38:55 +01:00
commit afee9152ed
8 changed files with 192 additions and 0 deletions

View file

@ -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"

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,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

@ -0,0 +1,4 @@
pub mod eq;
pub mod gt;
pub mod lt;
pub mod range;

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

View file

@ -3,6 +3,7 @@
extern crate itertools;
extern crate regex;
extern crate toml;
extern crate semver;
extern crate libimagstore;
extern crate libimagtag;