Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darky/glency
Tiny Gleam dependency injection. Make IO functions unit tests friendly.
https://github.com/darky/glency
dependency gleam injection
Last synced: about 2 months ago
JSON representation
Tiny Gleam dependency injection. Make IO functions unit tests friendly.
- Host: GitHub
- URL: https://github.com/darky/glency
- Owner: darky
- Created: 2024-07-07T17:03:25.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-09-21T17:40:21.000Z (4 months ago)
- Last Synced: 2024-10-28T13:24:08.326Z (2 months ago)
- Topics: dependency, gleam, injection
- Language: Gleam
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# glency
[![Package Version](https://img.shields.io/hexpm/v/glency)](https://hex.pm/packages/glency)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/glency/)
![Erlang-compatible](https://img.shields.io/badge/target-erlang-a2003e)
![JavaScript-compatible](https://img.shields.io/badge/target-javascript-f1e05a)Tiny Gleam dependency injection. Make IO functions unit tests friendly.
```sh
gleam add glency
``````gleam
import glencytype Cat {
Cat(name: String, age: Int)
}pub fn main() {
glency.init_di() // Firstly init DI container on application startup{
// Mock implementation of `fetch_cat`
use <- glency.with_di(fetch_cat, fn(_cat_id) { Cat("Barsik", 7) })
fetch_cat(1) // will avoid IO, returns Barsik cat
}
}pub fn fetch_cat(cat_id: Int) {
use <- glency.di(fetch_cat, #(cat_id)) // Make IO function DI friendly
// Here production IO implementation of function
}
```Further documentation can be found at .
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
gleam shell # Run an Erlang shell
```