https://github.com/devtin/duckfficer-method-di
loads duckfficer-method entities from a path to provide a pleasure-di container
https://github.com/devtin/duckfficer-method-di
Last synced: about 1 year ago
JSON representation
loads duckfficer-method entities from a path to provide a pleasure-di container
- Host: GitHub
- URL: https://github.com/devtin/duckfficer-method-di
- Owner: devtin
- Created: 2021-02-07T16:54:33.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-15T14:21:24.000Z (over 4 years ago)
- Last Synced: 2025-02-17T16:42:58.921Z (about 1 year ago)
- Language: JavaScript
- Size: 186 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
duckfficer-method-di
loads duckfficer-method entities from a path to provide a pleasure-di container
## Installation
```sh
$ npm i duckfficer-method-di --save
# or
$ yarn add duckfficer-method-di
```
## Features
- [builds an object appending all method found in given paths](#builds-an-object-appending-all-method-found-in-given-paths)
- [validates input](#validates-input)
- [validates output](#validates-output)
- [emits events](#emits-events)
## builds an object appending all method found in given paths
```js
const container = duckfficerMethodDi({
Gateway: 'gateways',
Service: 'services'
}, {
baseDir: path.join(__dirname, './__tests__/fixtures')
})
const { OrderService } = container
t.deepEqual(await OrderService.payment({
id: '123',
amount: 99
}), {
id: '123',
result: 'paying 99$'
})
```
## validates input
```js
const container = duckfficerMethodDi({
Gateway: 'gateways',
Service: 'services'
}, {
baseDir: path.join(__dirname, './__tests__/fixtures')
})
const { PayPalGateway } = container
const { originalError } = await t.throwsAsync(() => PayPalGateway.pay('100'), {
message: 'Invalid input'
})
t.like(originalError, {
message: 'Invalid number'
})
```
## validates output
```js
const container = duckfficerMethodDi({
Gateway: 'gateways',
Service: 'services'
}, {
baseDir: path.join(__dirname, './__tests__/fixtures')
})
const { PayPalGateway } = container
const { originalError } = await t.throwsAsync(() => PayPalGateway.pay(0), {
message: 'Invalid output'
})
t.like(originalError, {
message: 'Invalid string'
})
```
## emits events
```js
const container = duckfficerMethodDi({
Gateway: 'gateways',
Service: 'services'
}, {
baseDir: path.join(__dirname, './__tests__/fixtures')
})
const { PayPalGateway } = container
PayPalGateway.on('Paid', (payload) => {
t.log(payload)
t.pass()
})
return PayPalGateway.pay(100)
```
### duckfficerMethodDi(pathResolvers, [baseDir], [methodsPath]) ⇒ Object
| Param | Type | Default |
| --- | --- | --- |
| pathResolvers | Object | |
| [baseDir] | String | process.cwd() |
| [methodsPath] | String | methods |
**Returns**: Object - container
* * *
### License
[MIT](https://opensource.org/licenses/MIT)
© 2020-present Martin Rafael Gonzalez