Added abstract method support to propParse()
parent
4037cc1343
commit
6fd31a8e76
13
lib/util.js
13
lib/util.js
|
@ -96,9 +96,10 @@ exports.defineSecureProp = function( obj, prop, value )
|
|||
*/
|
||||
exports.propParse = function( data, options )
|
||||
{
|
||||
var callback_prop = options.property || function() {},
|
||||
callback_method = options.method || function() {},
|
||||
callback = null;
|
||||
var callback_prop = options.property || function() {},
|
||||
callback_method = options.method || function() {},
|
||||
callback_abstract_method = options.abstractMethod || function() {},
|
||||
callback = null;
|
||||
|
||||
// for each of the given properties, determine what type of property we're
|
||||
// dealing with (in the classic OO sense)
|
||||
|
@ -108,7 +109,11 @@ exports.propParse = function( data, options )
|
|||
|
||||
if ( value instanceof Function )
|
||||
{
|
||||
callback = callback_method;
|
||||
// concrete or abstract?
|
||||
callback = ( exports.isAbstractMethod( value ) )
|
||||
? callback_abstract_method
|
||||
: callback_method
|
||||
;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
require( './common' );
|
||||
|
||||
var assert = require( 'assert' ),
|
||||
propParse = require( '../lib/util' ).propParse;
|
||||
var assert = require( 'assert' ),
|
||||
util = require( '../lib/util' );
|
||||
|
||||
var data = {
|
||||
// scalars (properties)
|
||||
|
@ -42,13 +42,17 @@ var data = {
|
|||
|
||||
// concrete method
|
||||
method: function() {},
|
||||
|
||||
// abstract method
|
||||
abstractMethod: util.createAbstractMethod(),
|
||||
};
|
||||
|
||||
|
||||
var props = {},
|
||||
methods = {};
|
||||
var props = {},
|
||||
methods = {},
|
||||
amethods = {};
|
||||
|
||||
propParse( data, {
|
||||
util.propParse( data, {
|
||||
property: function( name, value )
|
||||
{
|
||||
props[ name ] = value;
|
||||
|
@ -59,6 +63,11 @@ propParse( data, {
|
|||
{
|
||||
methods[ name ] = method;
|
||||
},
|
||||
|
||||
abstractMethod: function( name, def )
|
||||
{
|
||||
amethods[ name ] = def;
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
|
@ -76,6 +85,12 @@ propParse( data, {
|
|||
assert.equal(
|
||||
methods.method,
|
||||
data.method,
|
||||
"Property parser properly detects methods"
|
||||
"Property parser properly detects concrete methods"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
amethods.abstractMethod,
|
||||
data.abstractMethod,
|
||||
"Property parser properly detects abstract methods"
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue