summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-01-09 10:59:07 +0100
committerGitHub <noreply@github.com>2018-01-09 10:59:07 +0100
commit4d00554d8c2d5fe861f650fe4ec183b137d0a7f1 (patch)
treec619d83b37aa53031442df7782b4f616dad948be
parent15cc7d68055eefde46eceda648cc710388f6910c (diff)
parent5c2d15cf564938a299e58e3559e023f7a6997926 (diff)
downloadimag-4d00554d8c2d5fe861f650fe4ec183b137d0a7f1.zip
imag-4d00554d8c2d5fe861f650fe4ec183b137d0a7f1.tar.gz
Merge pull request #1181 from matthiasbeyer/libimagentryutil/init
libimagentryutil: init
-rw-r--r--Cargo.toml1
-rw-r--r--doc/src/05100-lib-entryutil.md6
-rw-r--r--doc/src/09020-changelog.md2
-rw-r--r--lib/domain/libimagcontact/Cargo.toml1
-rw-r--r--lib/domain/libimagcontact/src/contact.rs15
-rw-r--r--lib/domain/libimagcontact/src/error.rs1
-rw-r--r--lib/domain/libimagcontact/src/lib.rs1
-rw-r--r--lib/domain/libimagcontact/src/store.rs7
-rw-r--r--lib/domain/libimaghabit/Cargo.toml2
-rw-r--r--lib/domain/libimaghabit/src/error.rs1
-rw-r--r--lib/domain/libimaghabit/src/habit.rs38
-rw-r--r--lib/domain/libimaghabit/src/instance.rs15
-rw-r--r--lib/domain/libimaghabit/src/lib.rs2
-rw-r--r--lib/entry/libimagentryannotation/Cargo.toml1
-rw-r--r--lib/entry/libimagentryannotation/src/annotateable.rs16
-rw-r--r--lib/entry/libimagentryannotation/src/error.rs1
-rw-r--r--lib/entry/libimagentryannotation/src/lib.rs1
-rw-r--r--lib/entry/libimagentryref/Cargo.toml1
-rw-r--r--lib/entry/libimagentryref/src/error.rs1
-rw-r--r--lib/entry/libimagentryref/src/lib.rs1
-rw-r--r--lib/entry/libimagentryref/src/reference.rs11
-rw-r--r--lib/entry/libimagentryref/src/refstore.rs4
-rw-r--r--lib/entry/libimagentryutil/Cargo.toml28
l---------lib/entry/libimagentryutil/README.md1
-rw-r--r--lib/entry/libimagentryutil/src/error.rs32
-rw-r--r--lib/entry/libimagentryutil/src/isa.rs129
-rw-r--r--lib/entry/libimagentryutil/src/lib.rs47
27 files changed, 316 insertions, 50 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 6f51c55..c800dc4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -44,6 +44,7 @@ members = [
"lib/entry/libimagentrymarkdown",
"lib/entry/libimagentryref",
"lib/entry/libimagentrytag",
+ "lib/entry/libimagentryutil",
"lib/entry/libimagentryview",
"lib/etc/libimaginteraction",
"lib/etc/libimagnotification",
diff --git a/doc/src/05100-lib-entryutil.md b/doc/src/05100-lib-entryutil.md
new file mode 100644
index 0000000..2197699
--- /dev/null
+++ b/doc/src/05100-lib-entryutil.md
@@ -0,0 +1,6 @@
+## libimagentryutil
+
+This library contains utilities for working with
+`libimagstore::store::Entry` objects where the functionality does not
+necessarily belong into `libimagstore`.
+
diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md
index 03bbb79..eeb7339 100644
--- a/doc/src/09020-changelog.md
+++ b/doc/src/09020-changelog.md
@@ -29,6 +29,8 @@ This section contains the changelog from the last release to the next release.
* `libimagstore::store::Store::retrieve_copy` was renamed to
`libimagstore::store::Store::get_copy`, which describes the semantics of
the function way better.
+ * `libimagentryutil` was introduced, a library for helpers for
+ `libimagstore::store::Entry` handling and writing extension-writing.
* Minor changes
* Internals were refactored from `match`ing all the things into function
chaining
diff --git a/lib/domain/libimagcontact/Cargo.toml b/lib/domain/libimagcontact/Cargo.toml
index ef3d35d..90d4a75 100644
--- a/lib/domain/libimagcontact/Cargo.toml
+++ b/lib/domain/libimagcontact/Cargo.toml
@@ -23,4 +23,5 @@ vobject = "0.4"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
libimagentryref = { version = "0.6.0", path = "../../../lib/entry/libimagentryref/" }
+libimagentryutil = { version = "0.6.0", path = "../../../lib/entry/libimagentryutil/" }
diff --git a/lib/domain/libimagcontact/src/contact.rs b/lib/domain/libimagcontact/src/contact.rs
index 14a80e3..6b11212 100644
--- a/lib/domain/libimagcontact/src/contact.rs
+++ b/lib/domain/libimagcontact/src/contact.rs
@@ -20,14 +20,12 @@
use std::ops::Deref;
use vobject::Component;
-use toml::Value;
-use toml_query::read::TomlValueReadExt;
use libimagstore::store::Entry;
use libimagentryref::reference::Ref;
+use libimagentryutil::isa::Is;
+use libimagentryutil::isa::IsKindHeaderPathProvider;
-use error::ContactError as CE;
-use error::ContactErrorKind as CEK;
use error::Result;
use util;
@@ -46,15 +44,12 @@ pub trait Contact : Ref {
}
+provide_kindflag_path!(pub IsContact, "contact.is_contact");
+
impl Contact for Entry {
fn is_contact(&self) -> Result<bool> {
- let location = "contact.marker";
- match self.get_header().read(location)? {
- Some(&Value::Boolean(b)) => Ok(b),
- Some(_) => Err(CE::from_kind(CEK::HeaderTypeError("boolean", location))),
- None => Ok(false)
- }
+ self.is::<IsContact>().map_err(From::from)
}
fn get_contact_data(&self) -> Result<ContactData> {
diff --git a/lib/domain/libimagcontact/src/error.rs b/lib/domain/libimagcontact/src/error.rs
index c3c8147..93f5d15 100644
--- a/lib/domain/libimagcontact/src/error.rs
+++ b/lib/domain/libimagcontact/src/error.rs
@@ -28,6 +28,7 @@ error_chain! {
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
RefError(::libimagentryref::error::RefError, ::libimagentryref::error::RefErrorKind);
VObjectError(::vobject::error::VObjectError, ::vobject::error::VObjectErrorKind);
+ EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind);
}
foreign_links {
diff --git a/lib/domain/libimagcontact/src/lib.rs b/lib/domain/libimagcontact/src/lib.rs
index efdb8a6..134a320 100644
--- a/lib/domain/libimagcontact/src/lib.rs
+++ b/lib/domain/libimagcontact/src/lib.rs
@@ -42,6 +42,7 @@ extern crate toml_query;
#[macro_use] extern crate libimagstore;
extern crate libimagerror;
extern crate libimagentryref;
+#[macro_use] extern crate libimagentryutil;
module_entry_path_mod!("contact");
diff --git a/lib/domain/libimagcontact/src/store.rs b/lib/domain/libimagcontact/src/store.rs
index 770c08f..505fa57 100644
--- a/lib/domain/libimagcontact/src/store.rs
+++ b/lib/domain/libimagcontact/src/store.rs
@@ -20,15 +20,15 @@
use std::path::PathBuf;
use vobject::parse_component;
-use toml::Value;
-use toml_query::insert::TomlValueInsertExt;
use libimagstore::store::Store;
use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreIdIterator;
use libimagentryref::refstore::RefStore;
use libimagentryref::flags::RefFlags;
+use libimagentryutil::isa::Is;
+use contact::IsContact;
use error::Result;
use util;
@@ -71,8 +71,7 @@ impl<'a> ContactStore<'a> for Store {
RefStore::create(self, p.clone(), flags)
.map_err(From::from)
.and_then(|mut entry| {
- entry.get_header_mut()
- .insert("contact.marker", Value::Boolean(true))
+ entry.set_isflag::<IsContact>()
.map_err(From::from)
.map(|_| entry)
})
diff --git a/lib/domain/libimaghabit/Cargo.toml b/lib/domain/libimaghabit/Cargo.toml
index cde44ab..8025734 100644
--- a/lib/domain/libimaghabit/Cargo.toml
+++ b/lib/domain/libimaghabit/Cargo.toml
@@ -19,10 +19,10 @@ log = "0.3"
toml = "0.4"
toml-query = "0.4.0"
error-chain = "0.11"
-is-match = "0.1"
kairos = "0.1.0-beta-2"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
libimagentryedit = { version = "0.6.0", path = "../../../lib/entry/libimagentryedit" }
libimagentrylink = { version = "0.6.0", path = "../../../lib/entry/libimagentrylink" }
+libimagentryutil = { version = "0.6.0", path = "../../../lib/entry/libimagentryutil" }
diff --git a/lib/domain/libimaghabit/src/error.rs b/lib/domain/libimaghabit/src/error.rs
index 71abfb2..6eeee32 100644
--- a/lib/domain/libimaghabit/src/error.rs
+++ b/lib/domain/libimaghabit/src/error.rs
@@ -26,6 +26,7 @@ error_chain! {
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind);
KairosError(::kairos::error::KairosError, ::kairos::error::KairosErrorKind);
+ EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind);
}
foreign_links {
diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs
index 2979410..37bce21 100644
--- a/lib/domain/libimaghabit/src/habit.rs
+++ b/lib/domain/libimaghabit/src/habit.rs
@@ -31,6 +31,7 @@ use iter::HabitInstanceStoreIdIterator;
use util::date_to_string;
use util::IsHabitCheck;
use util::get_string_header_from_entry;
+use instance::IsHabitInstance;
use libimagentrylink::internal::InternalLinker;
use libimagstore::store::Store;
@@ -39,6 +40,8 @@ use libimagstore::store::Entry;
use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
use libimagstore::storeid::StoreIdIterator;
+use libimagentryutil::isa::Is;
+use libimagentryutil::isa::IsKindHeaderPathProvider;
/// A HabitTemplate is a "template" of a habit. A user may define a habit "Eat vegetable".
/// If the user ate a vegetable, she should create a HabitInstance from the Habit with the
@@ -81,6 +84,8 @@ pub trait HabitTemplate : Sized {
fn instance_id_for(habit_name: &String, habit_date: &NaiveDate) -> Result<StoreId>;
}
+provide_kindflag_path!(pub IsHabitTemplate, "habit.template.is_habit_template");
+
impl HabitTemplate for Entry {
fn create_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate) -> Result<FileLockEntry<'a>> {
@@ -93,10 +98,11 @@ impl HabitTemplate for Entry {
.map_err(From::from)
.and_then(|mut entry| {
{
+ let _ = entry.set_isflag::<IsHabitInstance>()?;
let hdr = entry.get_header_mut();
- hdr.insert("habit.instance.name", Value::String(name))?;
- hdr.insert("habit.instance.date", Value::String(date))?;
- hdr.insert("habit.instance.comment", Value::String(comment))?;
+ let _ = hdr.insert("habit.instance.name", Value::String(name))?;
+ let _ = hdr.insert("habit.instance.date", Value::String(date))?;
+ let _ = hdr.insert("habit.instance.comment", Value::String(comment))?;
}
Ok(entry)
})
@@ -190,16 +196,7 @@ impl HabitTemplate for Entry {
/// Check whether the instance is a habit by checking its headers for the habit data
fn is_habit_template(&self) -> Result<bool> {
- [
- "habit.template.name",
- "habit.template.basedate",
- "habit.template.comment",
- ].iter().fold(Ok(true), |acc, path| acc.and_then(|_| {
- self.get_header()
- .read(path)
- .map(|o| is_match!(o, Some(&Value::String(_))))
- .map_err(From::from)
- }))
+ self.is::<IsHabitTemplate>().map_err(From::from)
}
fn habit_name(&self) -> Result<String> {
@@ -248,11 +245,13 @@ pub mod builder {
use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
use libimagstore::store::FileLockEntry;
+ use libimagentryutil::isa::Is;
use error::HabitError as HE;
use error::HabitErrorKind as HEK;
use error::*;
use util::date_to_string;
+ use habit::IsHabitTemplate;
pub struct HabitBuilder {
name: Option<String>,
@@ -324,10 +323,15 @@ pub mod builder {
debug!("Creating entry in store for: {:?}", sid);
let mut entry = try!(store.create(sid));
- try!(entry.get_header_mut().insert("habit.template.name", Value::String(name)));
- try!(entry.get_header_mut().insert("habit.template.basedate", Value::String(date)));
- try!(entry.get_header_mut().insert("habit.template.recurspec", Value::String(recur)));
- try!(entry.get_header_mut().insert("habit.template.comment", Value::String(comment)));
+ let _ = entry.set_isflag::<IsHabitTemplate>()?;
+ {
+ let h = entry.get_header_mut();
+ let _ = h.insert("habit.template.name", Value::String(name))?;
+ let _ = h.insert("habit.template.basedate", Value::String(date))?;
+ let _ = h.insert("habit.template.recurspec", Value::String(recur))?;
+ let _ = h.insert("habit.template.comment", Value::String(comment))?;
+ }
+
if let Some(until) = self.untildate {
let until = date_to_string(&until);
try!(entry.get_header_mut().insert("habit.template.until", Value::String(until)));
diff --git a/lib/domain/libimaghabit/src/instance.rs b/lib/domain/libimaghabit/src/instance.rs
index 773ccab..1b66f04 100644
--- a/lib/domain/libimaghabit/src/instance.rs
+++ b/lib/domain/libimaghabit/src/instance.rs
@@ -26,6 +26,8 @@ use error::*;
use util::*;
use libimagstore::store::Entry;
+use libimagentryutil::isa::Is;
+use libimagentryutil::isa::IsKindHeaderPathProvider;
/// An instance of a habit is created for each time a habit is done.
///
@@ -45,18 +47,11 @@ pub trait HabitInstance {
fn get_template_name(&self) -> Result<String>;
}
+provide_kindflag_path!(pub IsHabitInstance, "habit.instance.is_habit_instance");
+
impl HabitInstance for Entry {
fn is_habit_instance(&self) -> Result<bool> {
- [
- "habit.instance.name",
- "habit.instance.date",
- "habit.instance.comment",
- ].iter().fold(Ok(true), |acc, path| acc.and_then(|_| {
- self.get_header()
- .read(path)
- .map(|o| is_match!(o, Some(&Value::String(_))))
- .map_err(From::from)
- }))
+ self.is::<IsHabitInstance>().map_err(From::from)
}
fn get_date(&self) -> Result<NaiveDate> {
diff --git a/lib/domain/libimaghabit/src/lib.rs b/lib/domain/libimaghabit/src/lib.rs
index 62e18f4..06545d6 100644
--- a/lib/domain/libimaghabit/src/lib.rs
+++ b/lib/domain/libimaghabit/src/lib.rs
@@ -23,12 +23,12 @@ extern crate toml_query;
extern crate kairos;
#[macro_use] extern crate log;
#[macro_use] extern crate error_chain;
-#[macro_use] extern crate is_match;
#[macro_use] extern crate libimagstore;
extern crate libimagerror;
extern crate libimagentryedit;
extern crate libimagentrylink;
+#[macro_use] extern crate libimagentryutil;
module_entry_path_mod!("habit");
diff --git a/lib/entry/libimagentryannotation/Cargo.toml b/lib/entry/libimagentryannotation/Cargo.toml
index 1df5834..83c48f7 100644
--- a/lib/entry/libimagentryannotation/Cargo.toml
+++ b/lib/entry/libimagentryannotation/Cargo.toml
@@ -24,3 +24,4 @@ error-chain = "0.11"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
libimagentrylink = { version = "0.6.0", path = "../../../lib/entry/libimagentrylink" }
+libimagentryutil = { version = "0.6.0", path = "../../../lib/entry/libimagentryutil" }
diff --git a/lib/entry/libimagentryannotation/src/annotateable.rs b/lib/entry/libimagentryannotation/src/annotateable.rs
index aa02772..3210f28 100644
--- a/lib/entry/libimagentryannotation/src/annotateable.rs
+++ b/lib/entry/libimagentryannotation/src/annotateable.rs
@@ -25,6 +25,8 @@ use libimagstore::store::Store;
use libimagstore::storeid::IntoStoreId;
use libimagstore::storeid::StoreIdIterator;
use libimagentrylink::internal::InternalLinker;
+use libimagentryutil::isa::Is;
+use libimagentryutil::isa::IsKindHeaderPathProvider;
use toml_query::read::TomlValueReadExt;
use toml_query::insert::TomlValueInsertExt;
@@ -43,6 +45,8 @@ pub trait Annotateable {
fn is_annotation(&self) -> Result<bool>;
}
+provide_kindflag_path!(IsAnnotation, "annotation.is_annotation");
+
impl Annotateable for Entry {
/// Annotate an entry, returns the new entry which is used to annotate
@@ -52,9 +56,10 @@ impl Annotateable for Entry {
.map_err(From::from)
.and_then(|mut anno| {
{
- let header = anno.get_header_mut();
- header.insert("annotation.is_annotation", Value::Boolean(true))?;
- header.insert("annotation.name", Value::String(String::from(ann_name)))?;
+ let _ = anno.set_isflag::<IsAnnotation>()?;
+ let _ = anno
+ .get_header_mut()
+ .insert("annotation.name", Value::String(String::from(ann_name)))?;
}
Ok(anno)
})
@@ -96,10 +101,7 @@ impl Annotateable for Entry {
}
fn is_annotation(&self) -> Result<bool> {
- self.get_header()
- .read("annotation.is_annotation")?
- .map(|val| val.as_bool().unwrap_or(false))
- .ok_or(AE::from_kind(AEK::HeaderTypeError))
+ self.is::<IsAnnotation>().map_err(From::from)
}
}
diff --git a/lib/entry/libimagentryannotation/src/error.rs b/lib/entry/libimagentryannotation/src/error.rs
index 8e25004..8320451 100644
--- a/lib/entry/libimagentryannotation/src/error.rs
+++ b/lib/entry/libimagentryannotation/src/error.rs
@@ -25,6 +25,7 @@ error_chain! {
links {
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind);
+ EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind);
}
foreign_links {
diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs
index 3bc5ad4..36cc8af 100644
--- a/lib/entry/libimagentryannotation/src/lib.rs
+++ b/lib/entry/libimagentryannotation/src/lib.rs
@@ -42,6 +42,7 @@ extern crate toml_query;
#[macro_use] extern crate libimagstore;
extern crate libimagerror;
extern crate libimagentrylink;
+#[macro_use] extern crate libimagentryutil;
module_entry_path_mod!("annotations");
diff --git a/lib/entry/libimagentryref/Cargo.toml b/lib/entry/libimagentryref/Cargo.toml
index 4a791e4..3060bf1 100644
--- a/lib/entry/libimagentryref/Cargo.toml
+++ b/lib/entry/libimagentryref/Cargo.toml
@@ -31,3 +31,4 @@ walkdir = "1"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
libimagentrylist = { version = "0.6.0", path = "../../../lib/entry/libimagentrylist" }
+libimagentryutil = { version = "0.6.0", path = "../../../lib/entry/libimagentryutil" }
diff --git a/lib/entry/libimagentryref/src/error.rs b/lib/entry/libimagentryref/src/error.rs
index f519b8c..e2159f6 100644
--- a/lib/entry/libimagentryref/src/error.rs
+++ b/lib/entry/libimagentryref/src/error.rs
@@ -26,6 +26,7 @@ error_chain! {
ListError(::libimagentrylist::error::ListError, ::libimagentrylist::error::ListErrorKind);
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
TomlQueryError(::toml_query::error::Error, ::toml_query::error::ErrorKind);
+ EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind);
}
foreign_links {
diff --git a/lib/entry/libimagentryref/src/lib.rs b/lib/entry/libimagentryref/src/lib.rs
index 2ef2556..ea4305d 100644
--- a/lib/entry/libimagentryref/src/lib.rs
+++ b/lib/entry/libimagentryref/src/lib.rs
@@ -45,6 +45,7 @@ extern crate walkdir;
#[macro_use] extern crate libimagstore;
extern crate libimagerror;
extern crate libimagentrylist;
+#[macro_use] extern crate libimagentryutil;
#[macro_use] extern crate error_chain;
module_entry_path_mod!("ref");
diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs
index 9c20011..78c9d44 100644
--- a/lib/entry/libimagentryref/src/reference.rs
+++ b/lib/entry/libimagentryref/src/reference.rs
@@ -25,6 +25,8 @@ use std::fs::File;
use std::fs::Permissions;
use libimagstore::store::Entry;
+use libimagentryutil::isa::Is;
+use libimagentryutil::isa::IsKindHeaderPathProvider;
use toml::Value;
use toml_query::read::TomlValueReadExt;
@@ -38,6 +40,9 @@ use hasher::*;
pub trait Ref {
+ /// Check whether the underlying object is actually a ref
+ fn is_ref(&self) -> Result<bool>;
+
/// Get the hash from the path of the ref
fn get_path_hash(&self) -> Result<String>;
@@ -113,9 +118,15 @@ pub trait Ref {
fn get_current_permissions(&self) -> Result<Permissions>;
}
+provide_kindflag_path!(pub IsRef, "ref.is_ref");
impl Ref for Entry {
+ /// Check whether the underlying object is actually a ref
+ fn is_ref(&self) -> Result<bool> {
+ self.is::<IsRef>().map_err(From::from)
+ }
+
/// Get the hash from the path of the ref
fn get_path_hash(&self) -> Result<String> {
self.get_location()
diff --git a/lib/entry/libimagentryref/src/refstore.rs b/lib/entry/libimagentryref/src/refstore.rs
index 8a7413b..5d8fc48 100644
--- a/lib/entry/libimagentryref/src/refstore.rs
+++ b/lib/entry/libimagentryref/src/refstore.rs
@@ -26,6 +26,7 @@ use libimagstore::storeid::IntoStoreId;
use libimagstore::storeid::StoreId;
use libimagstore::storeid::StoreIdIterator;
use libimagstore::store::Store;
+use libimagentryutil::isa::Is;
use toml::Value;
@@ -34,6 +35,7 @@ use error::RefError as RE;
use error::ResultExt;
use error::Result;
use flags::RefFlags;
+use reference::IsRef;
use hasher::*;
use module_path::ModuleEntryPath;
use util::*;
@@ -282,6 +284,8 @@ impl RefStore for Store {
}
}
+ let _ = fle.set_isflag::<IsRef>()?;
+
Ok(fle)
}
diff --git a/lib/entry/libimagentryutil/Cargo.toml b/lib/entry/libimagentryutil/Cargo.toml
new file mode 100644
index 0000000..540a4b5
--- /dev/null
+++ b/lib/entry/libimagentryutil/Cargo.toml
@@ -0,0 +1,28 @@
+[package]
+name = "libimagentryutil"
+version = "0.6.0"
+authors = ["Matthias Beyer <mail@beyermatthias.de>"]
+
+description = "Library for the imag core distribution"
+
+keywords = ["imag", "PIM", "personal", "information", "management"]
+readme = "../../../README.md"
+license = "LGPL-2.1"
+
+documentation = "https://matthiasbeyer.github.io/imag/imag_documentation/index.html"
+repository = "https://github.com/matthiasbeyer/imag"
+homepage = "http://imag-pim.org"
+
+[badges]
+travis-ci = { repository = "matthiasbeyer/imag" }
+is-it-maintained-issue-resolution = { repository = "matthiasbeyer/imag" }
+is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
+maintenance = { status = "actively-developed" }
+
+[dependencies]
+toml = "0.4"
+toml-query = "0.4"
+error-chain = "0.11"
+
+libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
+libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" }
diff --git a/lib/entry/libimagentryutil/README.md b/lib/entry/libimagentryutil/README.md
new file mode 120000
index 0000000..b78ac8e
--- /dev/null
+++ b/lib/entry/libimagentryutil/README.md
@@ -0,0 +1 @@
+../../../doc/src/05100-lib-entryutil.md \ No newline at end of file
diff --git a/lib/entry/libimagentryutil/src/error.rs b/lib/entry/libimagentryutil/src/error.rs
new file mode 100644
index 0000000..16b540f
--- /dev/null
+++ b/lib/entry/libimagentryutil/src/error.rs
@@ -0,0 +1,32 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+error_chain! {
+ types {
+ EntryUtilError, EntryUtilErrorKind, ResultExt, Result;
+ }
+
+ foreign_links {
+ TomlQueryError(::toml_query::error::Error);
+ }
+
+ errors {
+ }
+}
+
diff --git a/lib/entry/libimagentryutil/src/isa.rs b/lib/entry/libimagentryutil/src/isa.rs
new file mode 100644
index 0000000..566c638
--- /dev/null
+++ b/lib/entry/libimagentryutil/src/isa.rs
@@ -0,0 +1,129 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use error::EntryUtilError as EUE;
+use error::Result;
+
+use toml::Value;
+use toml_query::read::TomlValueReadExt;
+use toml_query::insert::TomlValueInsertExt;
+
+/// Trait to check whether an entry is a certain kind of entry
+///
+/// If an entry is marked with a `bool` flag in the header to contain a certain amount of data (for
+/// example a "wiki" entry may provide some meta information in the `[wiki]` section of its header),
+/// this trait provides a check whether the entry has set the flag to `true` or `false`.
+///
+/// # Note
+///
+/// This trait is solely for library implementations, as convenience functionality for implementing
+/// some function like this:
+///
+/// # Example
+///
+/// ```
+/// # extern crate libimagstore;
+/// # #[macro_use]
+/// # extern crate libimagentryutil;
+///
+/// # use libimagentryutil::error::Result as Result;
+/// use libimagentryutil::isa::IsKindHeaderPathProvider;
+/// use libimagentryutil::isa::Is;
+///
+/// trait WikiArticle {
+/// fn is_wiki_article(&self) -> Result<bool>;
+/// // ...
+/// }
+///
+/// provide_kindflag_path!(IsWikiEntry, "wiki.is_entry");
+///
+/// impl WikiArticle for ::libimagstore::store::Entry {
+/// fn is_wiki_article(&self) -> Result<bool> {
+/// self.is::<IsWikiEntry>()
+/// }
+/// }
+///
+/// # fn main() { }
+/// ```
+///
+/// # See also
+///
+/// * Documentation for `IsKindHeaderPathProvider`
+/// * Helper macro `provide_kindflag_path!()`
+///
+pub trait Is {
+ fn is<T: IsKindHeaderPathProvider>(&self) -> Result<bool>;
+ fn set_isflag<T: IsKindHeaderPathProvider>(&mut self) -> Result<()>;
+}
+
+impl Is for ::libimagstore::store::Entry {
+ fn is<T: IsKindHeaderPathProvider>(&self) -> Result<bool> {
+ let field = T::kindflag_header_location();
+
+ match self.get_header().read(field) {
+ Ok(Some(&Value::Boolean(b))) => Ok(b),
+ Ok(Some(_)) => Err(format!("Field {} has not a boolean type", field)).map_err(EUE::from),
+ Ok(None) => Err(format!("Field {} not available", field)).map_err(EUE::from),
+ Err(e) => Err(EUE::from(e))
+ }
+ }
+
+ fn set_isflag<T: IsKindHeaderPathProvider>(&mut self) -> Result<()> {
+ self.get_header_mut()
+ .insert(T::kindflag_header_location(), Value::Boolean(true))
+ .map_err(EUE::from)
+ .map(|_| ())
+ }
+}
+
+
+/// The IsKindHeaderPathProvider trait provides a function `typeflag_header_location()` which
+/// returns a `toml-query` path.
+///
+/// This path points to a `bool` entry in the header of an entry which marks the entry to be an
+/// entry of a certain kind.
+///
+/// For example, an "Wiki" entry might contain a `true` at `"wiki.is_entry"` in the header.
+/// This trait provides `"wiki.is_entry"`.
+pub trait IsKindHeaderPathProvider {
+ fn kindflag_header_location() -> &'static str;
+}
+
+/// Create (pub/non-pub) type for providing a `kindflag_header_location()` implementation.
+#[macro_export]
+macro_rules! provide_kindflag_path {
+ (pub $entry_header_path_provider_type:ident, $path:expr) => {
+ pub struct $entry_header_path_provider_type;
+ provide_kindflag_path!(impl for $entry_header_path_provider_type, $path);
+ };
+
+ ($entry_header_path_provider_type:ident, $path:expr) => {
+ struct $entry_header_path_provider_type;
+ provide_kindflag_path!(impl for $entry_header_path_provider_type, $path);
+ };
+
+ (impl for $entry_header_path_provider_type:ident, $path:expr) => {
+ impl IsKindHeaderPathProvider for $entry_header_path_provider_type {
+ fn kindflag_header_location() -> &'static str {
+ $path
+ }
+ }
+ };
+}
+
diff --git a/lib/entry/libimagentryutil/src/lib.rs b/lib/entry/libimagentryutil/src/lib.rs
new file mode 100644
index 0000000..1298f52
--- /dev/null
+++ b/lib/entry/libimagentryutil/src/lib.rs
@@ -0,0 +1,47 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#![recursion_limit="256"]
+
+#![deny(
+ dead_code,
+ non_camel_case_types,
+ non_snake_case,
+ path_statements,
+ trivial_numeric_casts,
+ unstable_features,
+ unused_allocation,
+ unused_import_braces,
+ unused_imports,
+ unused_must_use,
+ unused_mut,
+ unused_qualifications,
+ while_true,
+)]
+
+extern crate toml;
+extern crate toml_query;
+#[macro_use] extern crate error_chain;
+
+extern crate libimagstore;
+extern crate libimagerror;
+
+pub mod error;
+pub mod isa;
+