An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

duckfficer-method-di


Version


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