forked from mikield/adonis-ally-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServiceProvider.js
61 lines (51 loc) · 1.24 KB
/
ServiceProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
/*
* adonis-auth
*
* (c) Vladyslav Gaysyuk <mikield@icloud.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
const { ServiceProvider } = require('@adonisjs/fold')
const _ = require('lodash')
const Drivers = {
vk: require('./Drivers/Vk'),
twitch: require('./Drivers/Twitch'),
mixer: require('./Drivers/Mixer')
}
class AllyServiceProvider extends ServiceProvider {
/**
* The register method called by ioc container
* as a life-cycle method
*
* @method register
*
* @return {void}
*/
register () {
this.app.singleton('@mikield/ally-extended', (app) => {
class DriverActivator{
constructor(){
this.UDriver = {}
}
use(name){
if(_.has(Drivers, name)){
this.UDriver[name] = Drivers[name]
}
return this
}
}
return new DriverActivator
})
}
boot(){
const AllyExtended = use('@mikield/ally-extended')
_.forEach(AllyExtended.UDriver, (implementation, name) => {
this.app.extend('Adonis/Addons/Ally', name, () => {
return this.app.make(implementation)
})
})
}
}
module.exports = AllyServiceProvider