a3 module loads any folder of code into an 'API Tree'.
npm install a3
First, require a3
:
a3 = require('a3')
Next :
apiTree = a3.buildApiTree('./app')
Options:
options:
moduleLoadedCallback: customCallback #(default callback loads all export methods of module)
allowDirectoryConflicts: true #(default is false, and throws exception when dir tree confilct found)
apiTree = a3.buildApiTree('./app', options)
Assuming we've got following code folders structure:
api\comments.coffee
api\posts.coffee
api\users.coffee
api\admin\users.coffee
api\admin\comments.coffee
With following file contents:
api\comments.coffee
exports.list ->
## some code
exports.add(comment) ->
## some code
api\posts.coffee
exports.list ->
## some code
exports.add(post) ->
## some code
api\users.coffee
exports.list ->
## some code
exports.add(user) ->
## some code
api\admin\users.coffee
exports.list ->
## some code
exports.remove(user) ->
## some code
api\admin\comments.coffee
exports.list ->
## some code
exports.remove(comment) ->
## some code
Invoke buildApiTree on api folder :
api = a3.buildApiTree('./api')
It will return following object with all modules in provided code folder loaded:
{
comments:{
list: [Function],
add: [Function]
},
posts: {
list: [Function],
add: [Function]
},
users: {
list: [Function],
add: [Function]
},
admin: { users:{
list: [Function],
remove: [Function]
},
comments:{
list: [Function],
remove: [Function]
}
}
}
To run the test suite first invoke the following command within the repo, installing the development dependencies:
npm install
then run:
jasmine-node --coffee spec
Copyright (c) 2011 Tadeusz Wójcik tadeuszwojcik@gmail.com
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.