Colt
A sequencing library with a chainable api
Example usage
API
var colt = require('colt')
colt
Is a colt api instance
colt.forge(), colt.create(), colt.new()
Creates a new colt api instance
colt1.mixin(colt2)
Extends colt1 with all the methods from colt2
colt.clone()
Returns a new colt api instance with all the methods from colt
colt.register(yourMethodName, function (content[, callback]))
Is used to register a method, content contains a name and a value object.
colt()
Returns an object which contains all colt methods you registered
yourMethodName
colt()yourMethodName
is the name of a method you registered using colt.register
colt().end, colt().fire, colt().exec
Are methods which accept a node type callback callback(err, res)
res
contains all values which get populated during the execution
How to register methods
// Register methodsvar colt = colt colt colt
More examples
// The main module returns a colt api instance// If you register methods on this instance, they will be global// and will be returned if you require colt.var colt = colt // create a new instancevar chain = colt // Or clone an instancechain = colt // You can use .mixin to inherit from specific colt instanceschain chain // Execute a registered methodvar res = { if err throw err // res.user is the result of the method defined in chain.load('set', ...} // exitchainchainchain
How we use it (sorry for the coffee-script)
describe 'User api:'-> // Colt version before @res = colt createUser'normalUser' createUser'adminUser'admin: true createDocumentForUser'document''normalUser'title: 'Foobar' enddone // What this would look like with asyncjs // This structures get really complex if you want // to create relations and depend on previous results before asyncseries : userSupportcreateUser @_userId = userid doneerruser : userSupportcreateDocument title: 'Foobar' user_id: @_userId done : userSupportcreateUseradmin: truedone @res = res doneerr it 'requires admin access to access users endpoint' requestget'/users' withUser@resnormalUser expect401 enddone it 'allows admins to access the page' requestget'/users' withUser@resadminUser expect200 enddone