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
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### Contributing
We welcome your contributions!

There are many ways you can contribute to this project. Since this project is in its adolescenct stage, the simplest way to contribute is to start using `Class Scaffolding`. (Please adhere to our adoption rules.)

### Adopter
You are welcome to download the product(s) and its source code for your use. By doing so, you are agreeing to the following responsibilities:

- Adhere to the [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
- Report any bugs, enhancement requests, or product suggestions using our [Issues Tracking](https://github.com/dsietz/class-scaffolding/issues)
- Submit any questions or comments for discussion about the this crate in the [Rust User Forum](https://users.rust-lang.org/)

### Developer
If you would like to get more involved and contribute to the code, (e.g.: fixing an issue or providing an enhancement), you are welcome to follow these steps:

>NOTE: In an effort to ensure compatibility, this project is restricted to the `STABLE RELEASE`

1. File a [request](https://github.com/dsietz/class-scaffolding/issues), (or select an [existing one](https://github.com/dsietz/class-scaffolding/issues)), and tag me with @dsietz on an issue. I'll then get you setup as a contributor.
2. Fork our [repository](https://github.com/dsietz/class-scaffolding)
3. Make the necessary code changes in your repo
4. Ensure that our [testing strategy and standards](./TESTING.md) are adhered as part of your development
5. Ensure that you have updated the [What's New](https://github.com/dsietz/class-scaffolding/blob/development/README.md#whats-new) section of the README file to include your changes
6. Submit a properly formatted [pull request](./PULL_REQUESTS.md) to merge your changes to our [development](https://github.com/dsietz/class-scaffolding/tree/development) branch

> As a note, all contributions are expected to follow [the Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).

#### Project
This project attempts to be an idiomatic rust library and to maintain a same structure. All source code is located in `src/`, and tests are in `tests/`.
39 changes: 39 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "scaffolding-core"
version = "0.1.0"
authors = ["dsietz <davidsietz@yahoo.com>"]
edition = "2021"
readme = "README.md"
license = "Apache-2.0"
keywords = ["sdk", "design", "development", "object-oriented", "class"]
categories = ["development-tools"]
description = "A software development kit that provides the scaffolding for building applications and services."
documentation = "https://docs.rs/scaffolding-core"
repository = "https://github.com/dsietz/scaffolding-core"
exclude = [
"examples/*",
"target/*",
"tests/*",
"benches/*",
]

[badges]
maintenance = {status = "actively-developed"}

[lib]
name = "class_scaffolding"
path = "src/lib.rs"
proc-macro = true

[dependencies]
derive = "1.0.0"
env_logger = "~0.10"
log = "~0.4"
quote = "1.0.28"
syn = "2.0.18"

[dependencies.uuid]
version = "1.3.3"
features = [
"v4",
]
File renamed without changes.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# class-scaffolding
Basic scaffolding for building OOD classes
# Class Scaffolding
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)


### Description
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
- [Class Scaffolding](#class-scaffolding)
- [Description](#description)
- [Table of Contents](#table-of-contents)
- [What's New](#whats-new)
- [How to Contribute](#how-to-contribute)
- [License](#license)

---

## What's New

Here's what's new ...

**0.1.0**
+ [Initial Release](https://github.com/dsietz/class-scaffolding/issues/1)

## How to Contribute

Details on how to contribute can be found in the [CONTRIBUTING](./CONTRIBUTING.md) file.

## License

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

See [LICENSE-APACHE "Apache License](./LICENSE-APACHE) for details.
10 changes: 10 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Testing Strategy and Standards

Our project follows the [Test Driven Development](https://en.wikipedia.org/wiki/Test-driven_development) approach. This means that all tests are written __prior__ to the development of the working code. Our goal is to have a 90% or high code coverage whenever released to the `Master` branch.

#### Standards
- All tests are located in the `tests` directory in their aligned test file (e.g.: .tests/facts.rs are thge tests for the profile::fact::Fact)
- All tests should have names that describe what they are testing (e.g.: new_fact_from_serialized)
- Tests should include both the positive and negative scenarios
- Test should cover exceptions and how they are handled
- There should be tests that represent how the users will use the crate's functionalitiy
38 changes: 38 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// extern crate log;
extern crate proc_macro;

use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput, parse::Parser};
use quote::quote;

/** reference material
* - https://github.com/eonm-abes/proc-macro-issue-minimal-example/tree/solution)
* - https://users.rust-lang.org/t/solved-derive-and-proc-macro-add-field-to-an-existing-struct/52307/3
*/

#[proc_macro_attribute]
pub fn add_field(_args: TokenStream, input: TokenStream) -> TokenStream {
let mut ast = parse_macro_input!(input as DeriveInput);
match &mut ast.data {
syn::Data::Struct(ref mut struct_data) => {
match &mut struct_data.fields {
syn::Fields::Named(fields) => {
fields
.named
.push(syn::Field::parse_named.parse2(quote! { pub a: String }).unwrap());
}
_ => {
()
}
}

return quote! {
#ast
}.into();
}
_ => panic!("`add_field` has to be used with structs "),
}
}

// pub mod scaffolding;

44 changes: 44 additions & 0 deletions src/scaffolding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! The `scaffolding` module provides the abstract class for developing object oriented classes.
//!
//!
//!
//!

extern crate uuid;

use uuid::Uuid;

// https://users.rust-lang.org/t/struct-inheritance-embedding-best-practice/10627/5
// https://doc.rust-lang.org/reference/attributes/derive.html
// https://stackoverflow.com/questions/53135923/how-to-write-a-custom-derive-macro
// https://docs.rs/syn/latest/syn/index.html#example-of-a-custom-derive

pub struct AbstractEntity {
pub uid: String,
}

impl AbstractEntity {
pub fn new() -> Self {
AbstractEntity {
uid: Uuid::new_v4().to_string(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;

fn get_abstract_entity() -> AbstractEntity {
let entity = AbstractEntity::new();

entity
}

#[test]
fn test_entity_id_ok() {
let entity = get_abstract_entity();
println!("{}", entity.uid);
assert_eq!(entity.uid.len(), 36);
}
}
33 changes: 33 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// #[macro_use]
extern crate class_scaffolding;

#[cfg(test)]
mod tests {
use class_scaffolding::add_field;
// #[derive(AnswerFn)]
// struct Struct;

#[test]
fn test_add_fields() {
#[add_field]
#[derive(Debug, Clone)]
struct Foo {}

let bar = Foo { a: "lorem ipsum".to_string()};
assert_eq!(format!("{:?}", bar), "{}");;
}

// fn test_macro3() {
// assert_eq!(42, answer());
// }

// // #[test]
// // fn test_macro2() {
// // #[derive(HelperAttr)]
// // struct MyObj {
// // #[helper]
// // field: (),
// // }
// // let s = MyObj();
// // }
}