Move reserved variable generation out of the endpoint builder and into the Endpoint class. Add an equivalent implementation for Event. Add the new reserved variables to sUtils.populate.

This commit is contained in:
Erik Erikson 2016-03-18 12:30:55 -07:00
parent a38621ba8a
commit a8096bc304
4 changed files with 18 additions and 8 deletions

View File

@ -46,7 +46,10 @@ module.exports = function(S) {
}
toObject() {
return S.utils.exportObject(_.cloneDeep(this));
let clone = _.cloneDeep(this);
clone.endpointName = this.getName();
clone.name = this.getFunction().getName(); // TODO Remove, legacy tight coupling of functions with endpoints. Make supplying this contingent on coupling?
return S.utils.exportObject(clone);
}
toObjectPopulated(options) {
@ -90,4 +93,4 @@ module.exports = function(S) {
return Endpoint;
};
};

View File

@ -32,7 +32,10 @@ module.exports = function(S) {
}
toObject() {
return S.utils.exportObject(_.cloneDeep(this));
let clone = _.cloneDeep(this);
clone.eventName = this.getName();
clone.name = this.getFunction().getName(); // TODO Remove, legacy tight coupling of functions with endpoints. Make supplying this contingent on coupling?
return S.utils.exportObject(clone);
}
toObjectPopulated(options) {
@ -57,6 +60,10 @@ module.exports = function(S) {
return _.assign(this, data);
}
getName() {
return this.name;
}
getProject() {
return S.getProject();
}
@ -73,4 +80,4 @@ module.exports = function(S) {
return Event;
};
};

View File

@ -139,9 +139,6 @@ module.exports = function(S) {
if (!_this.endpoint) BbPromise.reject(new SError(`Endpoint could not be found: ${_this.evt.options.endpointPath}#${_this.evt.options.endpointMethod}`));
// Set name variable in endpoint
_this.endpoint.name = _this.endpoint.getFunction().name; // the name of the function is a reserved variable that may be used to populate a value within the endpoint
// Set function name
_this.functionName = _this.endpoint.getFunction().getDeployedName({
stage: _this.evt.options.stage,

View File

@ -336,7 +336,10 @@ module.exports = {
}
// Reserved Variables
if (variableName === 'name' && data.name) value = data.name;
if (variableName === 'name' && data.name) value = data.name; // TODO Remove legacy variable that is semantically the functionName?
if (variableName === 'functionName' && data.functionName) value = data.functionName;
if (variableName === 'endpointName' && data.endpointName) value = data.endpointName;
if (variableName === 'eventName' && data.eventName) value = data.eventName;
// Populate
if (!value && !value !== "") {