Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "Apache-2.0"
name = "scaffolding-core"
readme = "README.md"
repository = "https://github.com/dsietz/scaffolding-core"
version = "0.1.0"
version = "0.2.0"

[badges]
maintenance = {status = "experimental"}
Expand All @@ -26,7 +26,10 @@ path = "src/lib.rs"

[dependencies]
chrono = "0.4.35"
scaffolding-macros = {path = "./scaffolding-macros", version = "0.1.0"}
scaffolding-macros = {path = "./scaffolding-macros", version = "0.2.0"}
serde = "1.0.197"
serde_derive = "1.0"
serde_json = "1.0"

[dependencies.uuid]
features = ["v4"]
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ For software development teams who appreciate a kick-start to their object orien
---

## What's New
| :warning: Please Note! |
| ----------------------------------------------------------------------------- |
| This crate is in an `beta` release phase and is only intended as experimental.|

!!! This crate is in an `Initial` release phase and is only intended as a PoC. !!!

**0.1.0**
+ [Added Metadata feature](https://github.com/dsietz/scaffolding-core/issues/2)
**0.2.0**
+ [Add Activity Logging](https://github.com/dsietz/scaffolding-core/issues/18)
+ [Provide the ability to Serialize and Deserialize](https://github.com/dsietz/scaffolding-core/issues/19)

## How to Contribute

Expand Down
5 changes: 4 additions & 1 deletion scaffolding-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scaffolding-macros"
version = "0.1.0"
version = "0.2.0"
authors = ["dsietz <davidsietz@yahoo.com>"]
edition = "2021"
readme = "README.md"
Expand Down Expand Up @@ -28,6 +28,9 @@ proc-macro = true
[dependencies]
quote = "1.0.35"
syn = {version = "2.0.53", features = ["full", "extra-traits"]}
serde = "1.0.197"
serde_derive = "1.0"
serde_json = "1.0"

[dev-dependencies]
serde_yaml = "0.9.27"
26 changes: 22 additions & 4 deletions scaffolding-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ use syn::Expr::Struct;
use syn::FieldValue;
use syn::Member;
use syn::{parse_macro_input, parse_quote, punctuated::Punctuated, ItemStruct, LitStr, Token};
// use serde::Serialize;

static METADATA: &str = "metadata";
static CORE_ATTRS: [&str; 5] = [
static CORE_ATTRS: [&str; 6] = [
"id",
"created_dtm",
"modified_dtm",
"inactive_dtm",
"expired_dtm",
"activity",
];

///
Expand Down Expand Up @@ -59,6 +61,13 @@ pub fn scaffolding_struct(args: TokenStream, input: TokenStream) -> TokenStream
.unwrap(),
);

// The list of activity performed on the object
fields.named.push(
syn::Field::parse_named
.parse2(quote! { activity: Vec<ActivityItem> })
.unwrap(),
);

// optional attributes
match attrs.contains(&METADATA.to_string()) {
true => {
Expand Down Expand Up @@ -110,9 +119,13 @@ fn impl_scaffolding(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
let gen = quote! {
impl Scaffolding for #name {
// fn set_id(mut &self, value: String) {
// self.id = value;
// }
fn get_activity(&self, name: String) -> Vec<ActivityItem>{
self.activity.iter().filter(|a| a.action == name).cloned().collect()
}

fn log_activity(&mut self, name: String, descr: String) {
self.activity.push(ActivityItem::new(name, descr));
}
}
};
gen.into()
Expand Down Expand Up @@ -149,6 +162,7 @@ pub fn scaffolding_fn(args: TokenStream, input: TokenStream) -> TokenStream {
"modified_dtm",
"inactive_dtm",
"expired_dtm",
"activity",
];

match attrs.contains(&METADATA.to_string()) {
Expand Down Expand Up @@ -201,6 +215,10 @@ pub fn scaffolding_fn(args: TokenStream, input: TokenStream) -> TokenStream {
let line: FieldValue = parse_quote! {expired_dtm: defaults::add_years(defaults::now(), 3)};
expr_struct.fields.insert(0, line);
}
"activity" => {
let line: FieldValue = parse_quote! {activity: Vec::new()};
expr_struct.fields.insert(0, line);
}
"metadata" => {
let line: FieldValue =
parse_quote! {metadata: BTreeMap::new()};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
// #[macro_use]
extern crate scaffolding_macros;


#[cfg(test)]
mod tests {
use scaffolding_macros::*;
use std::collections::BTreeMap;

#[derive(Debug, Clone)]
struct ActivityItem {
created_dtm: i64,
action: String,
description: String,
}

#[scaffolding_struct("metadata")]
#[derive(Debug, Clone)]
struct MyEntity {
Expand Down
14 changes: 14 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::error;
use std::fmt;

// struct
#[derive(Debug, Clone)]
pub struct DeserializeError;

//impl
impl fmt::Display for DeserializeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Unable to deserialize.")
}
}
impl error::Error for DeserializeError {}
Loading