Neurosis Prevention Mechanism
    Wondering what’s next for npm?Check out our public roadmap! »

    duckfficer-method-di

    1.0.1 • Public • Published

    duckfficer-method-di

    Version

    loads duckfficer-method entities from a path to provide a pleasure-di container

    Installation

    $ npm i duckfficer-method-di --save
    # or
    $ yarn add duckfficer-method-di

    Features

    builds an object appending all method found in given paths

    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

    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

    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

    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

    © 2020-present Martin Rafael Gonzalez tin@devtin.io

    Install

    npm i duckfficer-method-di

    DownloadsWeekly Downloads

    4

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    19.6 kB

    Total Files

    16

    Last publish

    Collaborators

    • avatar