From d75595e4d8d366f7c75535351d24bdd947261421 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 15 Mar 2016 23:11:30 +0100 Subject: [PATCH] Add VersionEq filter --- libimagentryfilter/src/builtin/header/mod.rs | 1 + .../src/builtin/header/version/eq.rs | 44 +++++++++++++++++++ .../src/builtin/header/version/mod.rs | 1 + 3 files changed, 46 insertions(+) create mode 100644 libimagentryfilter/src/builtin/header/version/eq.rs create mode 100644 libimagentryfilter/src/builtin/header/version/mod.rs diff --git a/libimagentryfilter/src/builtin/header/mod.rs b/libimagentryfilter/src/builtin/header/mod.rs index baece9f6..0d27f5b4 100644 --- a/libimagentryfilter/src/builtin/header/mod.rs +++ b/libimagentryfilter/src/builtin/header/mod.rs @@ -7,3 +7,4 @@ pub mod field_istype; pub mod field_lt; pub mod field_path; pub mod field_predicate; +pub mod version; diff --git a/libimagentryfilter/src/builtin/header/version/eq.rs b/libimagentryfilter/src/builtin/header/version/eq.rs new file mode 100644 index 00000000..f2be5a28 --- /dev/null +++ b/libimagentryfilter/src/builtin/header/version/eq.rs @@ -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) + } + +} + diff --git a/libimagentryfilter/src/builtin/header/version/mod.rs b/libimagentryfilter/src/builtin/header/version/mod.rs new file mode 100644 index 00000000..798e468e --- /dev/null +++ b/libimagentryfilter/src/builtin/header/version/mod.rs @@ -0,0 +1 @@ +pub mod eq;