#class #object-oriented #design #development #sdk

scaffolding-core

A software development kit that provides the scaffolding for building applications and services

7 releases (4 breaking)

0.4.0 Mar 31, 2024
0.3.0 Mar 30, 2024
0.2.0 Mar 30, 2024
0.1.0 Mar 29, 2024
0.0.3 Mar 25, 2024

#308 in Development tools

Download history 188/week @ 2024-03-19 463/week @ 2024-03-26 63/week @ 2024-04-02

714 downloads per month

Apache-2.0

36KB
239 lines

License Docs.rs Build/Test Discussions

Scaffolding Core

For software development teams who appreciate a kick-start to their object oriented development, this scaffolding library is a light-weight module that provides the basic structures and behavior that is the building block of all class intantiated objects. Unlike the practice of writing classes with the various approaches for building common functionality, this open source library helps you inherit these cross-class commonalities so you can focus on the differentiator that define your class.


Table of Contents


What's New

⚠️ Please Note!
This crate is in an beta release phase and is only intended as experimental.

0.4.0

Usage

Add Scaffolding to a struct and impl ::new() using macros and defaults

extern crate scaffolding_core;

use scaffolding_core::{defaults, ActivityItem, Note, Scaffolding, ScaffoldingNotes, ScaffoldingTags};
use scaffolding_macros::*;
use serde_derive::{Deserialize, Serialize};
// Required for scaffolding metadata functionality
use std::collections::BTreeMap;

// (1) Define the structure - Required
#[scaffolding_struct("metadata","notes","tags")]
#[derive(Debug, Clone, Deserialize, Serialize, Scaffolding, ScaffoldingNotes, ScaffoldingTags)]
struct MyEntity {
    a: bool,
    b: String,
}

impl MyEntity {
    // (2) Define the constructor - Optional
    //     Note: Any of the Scaffodling attributes that are set here 
    //           will not be overwritten when generated. For example
    //           the `id` attribute, if uncommented, would be ignored.
    #[scaffolding_fn("metadata","notes","tags")]
    fn new(arg: bool) -> Self {
        let msg = format!("You said it is {}", arg);
        Self {
            // id: "my unique identitifer".to_string(),
            a: arg,
            b: msg
        }
    }

    fn my_func(&self) -> String {
        "my function".to_string()
    }
}

let mut entity = MyEntity::new(true);

/* scaffolding attributes */
assert_eq!(entity.id.len(), "54324f57-9e6b-4142-b68d-1d4c86572d0a".len());
assert_eq!(entity.created_dtm, defaults::now());
assert_eq!(entity.modified_dtm, defaults::now());
// becomes inactive in 90 days
assert_eq!(entity.inactive_dtm, defaults::add_days(defaults::now(), 90));
// expires in 3 years
assert_eq!(entity.expired_dtm, defaults::add_years(defaults::now(), 3));

/* use the activity log functionality  */
// (1) Log an activity
entity.log_activity("cancelled".to_string(), "The customer has cancelled their service".to_string());
// (2) Get activities
assert_eq!(entity.get_activity("cancelled".to_string()).len(), 1);

/* use the notes functionality */
// (1) Insert a note
let note_id = entity.insert_note(
  "fsmith".to_string(),
  "This was updated".as_bytes().to_vec(),
  None,
);
// (2) Modify the note
entity.modify_note(
  note_id.clone(),
  "fsmith".to_string(),
  "This was updated again".as_bytes().to_vec(),
  Some("private".to_string()),
);
// (3) Read the note's content
let read_note = entity.get_note(note_id.clone()).unwrap().content_as_string().unwrap();
println!("{}", read_note);
// (4) Search for notes that contain the word `updated`
let search_results = entity.search_notes("updated".to_string());
assert_eq!(search_results.len(), 1);
// (5) Delete the note
entity.remove_note(note_id);

/* use the metadata functionality
   Note: `memtadata` is a BTreeMap<String, String>
          https://doc.rust-lang.org/std/collections/struct.BTreeMap.html
*/
entity.metadata.insert("field_1".to_string(), "myvalue".to_string());
assert_eq!(entity.metadata.len(), 1);

// manage tags
entity.add_tag("tag_1".to_string());
entity.add_tag("tag_2".to_string());
entity.add_tag("tag_3".to_string());
assert!(entity.has_tag("tag_1".to_string()));
entity.remove_tag("tag_2".to_string());
assert_eq!(entity.tags.len(), 2);

/* extended attributes */
assert_eq!(entity.a, true);
assert_eq!(entity.b, "You said it is true");

/* extended behavior */
assert_eq!(entity.my_func(), "my function");

How to Contribute

Details on how to contribute can be found in the CONTRIBUTING file.

License

The scaffolding-core project is primarily distributed under the terms of the Apache License (Version 2.0).

See LICENSE-APACHE "Apache License for details.

Dependencies

~1.8–2.8MB
~54K SLoC