function setupTransformer()

in transformer.js [91:148]


function setupTransformer(callback) {
    // set the default transformer
    var t = jsonToStringTransformer.bind(undefined);

    // set the transformer based on specified datatype of the stream
    if (process.env[STREAM_DATATYPE_ENV]) {
	var found = false;
	Object.keys(supportedDatatypeTransformerMappings).forEach(function(key) {
	    if (process.env[STREAM_DATATYPE_ENV] === key) {
		found = true;
	    }
	});

	if (found === true) {
	    // set the transformer class via a cross reference to the
	    // transformer mapping
	    if (debug) {
		console.log("Setting data transformer based on Stream Datatype configuration");
	    }
	    t = this[transformerRegistry[supportedDatatypeTransformerMappings[process.env[STREAM_DATATYPE_ENV]]]].bind(undefined);
	}
    } else {
	if (debug) {
	    console.log("No Stream Datatype Environment Configuration found");
	}
    }

    // check if the transformer has been overridden by environment settings
    if (process.env[TRANSFORMER_FUNCTION_ENV]) {
	console.log(process.env[TRANSFORMER_FUNCTION_ENV])
	var found = false;
	Object.keys(transformerRegistry).forEach(function(key) {
	    if (process.env[TRANSFORMER_FUNCTION_ENV] === transformerRegistry[key]) {
		found = true;
	    }
	});

	if (found === false) {
	    callback("Configured Transformer function " + process.env[TRANSFORMER_FUNCTION_ENV] + " is not a valid transformation method in the transformer.js module");
	} else {
	    if (debug) {
		console.log("Setting data transformer based on Transformer Override configuration");
	    }
	    // dynamically bind in the transformer function
	    t = this[process.env[TRANSFORMER_FUNCTION_ENV]].bind(undefined);
	}
    } else {
	if (debug) {
	    console.log("No Transformer Override Environment Configuration found");
	}
    }

    if (debug) {
	console.log("Using Transformer function " + t.name);
    }

    callback(null, t);
}