forked from adonisjs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceCollection.js
More file actions
88 lines (77 loc) · 1.47 KB
/
ResourceCollection.js
File metadata and controls
88 lines (77 loc) · 1.47 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict'
/**
* adonis-framework
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
const helpers = require('./helpers')
const util = require('../../lib/util')
const CatLog = require('cat-log')
const logger = new CatLog('adonis:framework')
class ResourceCollection {
constructor (route) {
this.route = route
}
/**
* binds action to the route, it will override
* the old action
*
* @param {String|Function} action
*
* @return {Object}
*
* @public
*/
bindAction (action) {
this.route.handler = action
return this
}
/**
* @see this.middleware
*/
middlewares () {
logger.warn('collection@middlewares: consider using method middleware, instead of middlewares')
return this.middleware.apply(this, arguments)
}
/**
* appends middlewares to the route
*
* @return {Object}
*
* @public
*/
middleware () {
helpers.appendMiddleware(
this.route,
util.spread.apply(this, arguments)
)
return this
}
/**
* assign name to the route
*
* @param {String} name
*
* @return {Object}
*
* @public
*/
as (name) {
this.route.name = name
return this
}
/**
* return json representation of the route
*
* @return {Object}
*
* @public
*/
toJSON () {
return this.route
}
}
module.exports = ResourceCollection