diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..581d20d --- /dev/null +++ b/CONTRIBUTING.md @@ -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/`. \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d9fa3fa --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "scaffolding-core" +version = "0.1.0" +authors = ["dsietz "] +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", +] diff --git a/LICENSE b/LICENSE-APACHE similarity index 100% rename from LICENSE rename to LICENSE-APACHE diff --git a/README.md b/README.md index 3a3ddb0..e221378 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..552ab68 --- /dev/null +++ b/TESTING.md @@ -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 \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..5a5f23e --- /dev/null +++ b/src/lib.rs @@ -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; + diff --git a/src/scaffolding.rs b/src/scaffolding.rs new file mode 100644 index 0000000..81ee28b --- /dev/null +++ b/src/scaffolding.rs @@ -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); + } +} diff --git a/tests/integration_test.rs b/tests/integration_test.rs new file mode 100644 index 0000000..90c6541 --- /dev/null +++ b/tests/integration_test.rs @@ -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(); + // // } +}