Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
512 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 ResourceMember { | ||
|
||
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('member@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 = ResourceMember |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.