summaryrefslogtreecommitdiffstats
path: root/libimagentryfilter
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-02-02 15:27:17 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-02-03 16:39:04 +0100
commit012ca4a4278764b9f90587bb550e48e7ba184acd (patch)
tree5dcc8e3c0c30ee2922a5852a4a4af4aedf94636d /libimagentryfilter
parent0fb331f25a5677c4d8aef3bc86b0c523f6d4b8c0 (diff)
Initialize structure for header builtins
Diffstat (limited to 'libimagentryfilter')
-rw-r--r--libimagentryfilter/src/builtin/content/mod.rs0
-rw-r--r--libimagentryfilter/src/builtin/header/field_eq.rs36
-rw-r--r--libimagentryfilter/src/builtin/header/field_path/element.rs18
-rw-r--r--libimagentryfilter/src/builtin/header/field_path/error.rs39
-rw-r--r--libimagentryfilter/src/builtin/header/field_path/mod.rs35
-rw-r--r--libimagentryfilter/src/builtin/header/mod.rs3
-rw-r--r--libimagentryfilter/src/builtin/mod.rs2
7 files changed, 133 insertions, 0 deletions
diff --git a/libimagentryfilter/src/builtin/content/mod.rs b/libimagentryfilter/src/builtin/content/mod.rs
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/libimagentryfilter/src/builtin/content/mod.rs
diff --git a/libimagentryfilter/src/builtin/header/field_eq.rs b/libimagentryfilter/src/builtin/header/field_eq.rs
new file mode 100644
index 00000000..fc4e1e77
--- /dev/null
+++ b/libimagentryfilter/src/builtin/header/field_eq.rs
@@ -0,0 +1,36 @@
+use libimagstore::store::Entry;
+
+use builtin::header::field_path::FieldPath;
+use filter::Filter;
+
+use toml::Value;
+
+/// Check whether certain header field in a entry is equal to a value
+pub struct FieldEq {
+ header_field_path: FieldPath,
+ expected_value: Value
+}
+
+impl FieldEq {
+
+ pub fn new(path: FieldPath, expected_value: Value) -> FieldEq {
+ FieldEq {
+ header_field_path: path,
+ expected_value: expected_value,
+ }
+ }
+
+}
+
+impl Filter for FieldEq {
+
+ fn filter(&self, e: &Entry) -> bool {
+ let header = e.get_header();
+ self.header_field_path
+ .walk(header)
+ .map(|v| self.expected_value == v.clone())
+ .unwrap_or(false)
+ }
+
+}
+
diff --git a/libimagentryfilter/src/builtin/header/field_path/element.rs b/libimagentryfilter/src/builtin/header/field_path/element.rs
new file mode 100644
index 00000000..044289aa
--- /dev/null
+++ b/libimagentryfilter/src/builtin/header/field_path/element.rs
@@ -0,0 +1,18 @@
+use std::fmt::{Display, Formatter};
+use std::fmt::Error as FmtError;
+
+#[derive(Debug)]
+pub struct FieldPathElement {
+ name: String
+}
+
+impl Display for FieldPathElement {
+
+ fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
+ try!(write!(fmt, "{}", self.name));
+ Ok(())
+ }
+
+}
+
+
diff --git a/libimagentryfilter/src/builtin/header/field_path/error.rs b/libimagentryfilter/src/builtin/header/field_path/error.rs
new file mode 100644
index 00000000..69703cbf
--- /dev/null
+++ b/libimagentryfilter/src/builtin/header/field_path/error.rs
@@ -0,0 +1,39 @@
+use std::fmt::{Display, Formatter};
+use std::fmt::Error as FmtError;
+use std::error::Error;
+
+use builtin::header::field_path::element::FieldPathElement;
+
+#[derive(Debug)]
+pub struct FieldPathParsingError {
+ source: String,
+ token: FieldPathElement
+}
+
+impl FieldPathParsingError {
+
+ pub fn new(source: String, token: FieldPathElement) -> FieldPathParsingError {
+ FieldPathParsingError { source: source, token: token }
+ }
+}
+
+impl Display for FieldPathParsingError {
+
+ fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
+ try!(write!(fmt, "Failed to compile '{}', failed at: '{}'", self.source, self.token));
+ Ok(())
+ }
+
+}
+
+impl Error for FieldPathParsingError {
+
+ fn description(&self) -> &str {
+ &self.source[..]
+ }
+
+ fn cause(&self) -> Option<&Error> {
+ None
+ }
+
+}
diff --git a/libimagentryfilter/src/builtin/header/field_path/mod.rs b/libimagentryfilter/src/builtin/header/field_path/mod.rs
new file mode 100644
index 00000000..0a8e61df
--- /dev/null
+++ b/libimagentryfilter/src/builtin/header/field_path/mod.rs
@@ -0,0 +1,35 @@
+use std::fmt::{Display, Formatter};
+use std::fmt::Error as FmtError;
+use std::error::Error;
+
+use toml::Value;
+
+pub mod element;
+pub mod error;
+
+use libimagstore::store::Entry;
+use libimagstore::store::EntryHeader;
+
+use builtin::header::field_path::element::FieldPathElement;
+use builtin::header::field_path::error::FieldPathParsingError;
+
+pub struct FieldPath {
+ elements: Vec<FieldPathElement>,
+}
+
+impl FieldPath {
+
+ pub fn new(elements: Vec<FieldPathElement>) -> FieldPath {
+ unimplemented!()
+ }
+
+ pub fn compile(source: String) -> Result<FieldPath, FieldPathParsingError> {
+ unimplemented!()
+ }
+
+ pub fn walk(&self, e: &EntryHeader) -> Option<Value> {
+ unimplemented!()
+ }
+
+}
+
diff --git a/libimagentryfilter/src/builtin/header/mod.rs b/libimagentryfilter/src/builtin/header/mod.rs
new file mode 100644
index 00000000..14b98d62
--- /dev/null
+++ b/libimagentryfilter/src/builtin/header/mod.rs
@@ -0,0 +1,3 @@
+pub mod field_eq;
+pub mod field_path;
+
diff --git a/libimagentryfilter/src/builtin/mod.rs b/libimagentryfilter/src/builtin/mod.rs
index e69de29b..260f1a1b 100644
--- a/libimagentryfilter/src/builtin/mod.rs
+++ b/libimagentryfilter/src/builtin/mod.rs
@@ -0,0 +1,2 @@
+pub mod content;
+pub mod header;