diff --git a/apps/fab.method.DELETE.js b/apps/fab.method.DELETE.js new file mode 100644 index 0000000..1002c93 --- /dev/null +++ b/apps/fab.method.DELETE.js @@ -0,0 +1,5 @@ +var fab = { method: require( "./fab.method" ).app }; + +exports.summary = "Shortcut for fab.method( 'DELETE' )."; + +exports.app = fab.method( "DELETE" ) \ No newline at end of file diff --git a/apps/fab.method.GET.js b/apps/fab.method.GET.js new file mode 100644 index 0000000..10f82cb --- /dev/null +++ b/apps/fab.method.GET.js @@ -0,0 +1,5 @@ +var fab = { method: require( "./fab.method" ).app }; + +exports.summary = "Shortcut for fab.method( 'GET' )."; + +exports.app = fab.method( "GET" ) \ No newline at end of file diff --git a/apps/fab.method.POST.js b/apps/fab.method.POST.js new file mode 100644 index 0000000..bc3f714 --- /dev/null +++ b/apps/fab.method.POST.js @@ -0,0 +1,5 @@ +var fab = { method: require( "./fab.method" ).app }; + +exports.summary = "Shortcut for fab.method( 'POST' )."; + +exports.app = fab.method( "POST" ) \ No newline at end of file diff --git a/apps/fab.method.PUT.js b/apps/fab.method.PUT.js new file mode 100644 index 0000000..ea190e4 --- /dev/null +++ b/apps/fab.method.PUT.js @@ -0,0 +1,5 @@ +var fab = { method: require( "./fab.method" ).app }; + +exports.summary = "Shortcut for fab.method( 'PUT' )."; + +exports.app = fab.method( "PUT" ) \ No newline at end of file diff --git a/apps/fab.method.js b/apps/fab.method.js index 0848e95..3d97e10 100644 --- a/apps/fab.method.js +++ b/apps/fab.method.js @@ -1,36 +1,30 @@ exports.summary = "Takes one more more method names, and returns a ternary app that passes the request to the first app when the request method matches, and to the second app otherwise."; -method = exports.app = ( function( names ) { - for ( var name; name = names.pop(); ) method[ name ] = method( name ); - - return method; - - function method() { - var - methods = {}, - len = arguments.length; +method = exports.app = function( names ) { + var + methods = {}, + len = arguments.length; + + for ( var i = 0; i < len; i++ ) { + methods[ arguments[ i ] ] = true; + } - for ( var i = 0; i < len; i++ ) { - methods[ arguments[ i ] ] = true; - } - - return function( hit ) { - return function( miss ) { - return function() { - var out = this; - return function( head ) { - var app = head.method in methods ? hit : miss; - - app = app.call( out ); - if ( app ) app = app( head ); - - return app; - } + return function( hit ) { + return function( miss ) { + return function() { + var out = this; + return function( head ) { + var app = head.method in methods ? hit : miss; + + app = app.call( out ); + if ( app ) app = app( head ); + + return app; } } } } -})( [ "GET", "POST", "PUT", "DELETE" ] ); +} exports.tests = ( function() { var ok = function(){ this({ body: true }) }