Skip to content

Commit

Permalink
Changed indentation style
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiel committed Apr 11, 2015
1 parent 98655d2 commit d7fcd7b
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions lib/field-alias-plugin.js
Expand Up @@ -15,13 +15,13 @@
* @param {Any} value Value to set at the end of key chain
*/
function _propertyInflector(document, property ,value){
if(property.length > 1){
document[property[0]] = document[property[0]] || {};
return _propertyInflector( document[property[0]], property.slice(1), value);
}else{
document[property[0]] = value;
return document;
}
if(property.length > 1){
document[property[0]] = document[property[0]] || {};
return _propertyInflector( document[property[0]], property.slice(1), value);
}else{
document[property[0]] = value;
return document;
}
}

/**
Expand All @@ -30,55 +30,55 @@ function _propertyInflector(document, property ,value){
* @returns {Function} Methods (Mongoose intended) for schema
*/
function _toAliasedFieldsObjectProvider(schema){
return function toAliasedFieldsObject(){
var document = {};
for(var p in schema.paths){
var property = schema.paths[p];
if(this.get(property.path) !== undefined){
if( property.options.alias && 'string' == typeof property.options.alias && property.options.alias !== ''){
var alias = property.options.alias.split('.');
_propertyInflector(document,alias, this.get(property.path) );
}else{
document[property.path] = this.get(property.path);
}
}
}
return document;
};
return function toAliasedFieldsObject(){
var document = {};
for(var p in schema.paths){
var property = schema.paths[p];
if(this.get(property.path) !== undefined){
if( property.options.alias && 'string' == typeof property.options.alias && property.options.alias !== ''){
var alias = property.options.alias.split('.');
_propertyInflector(document,alias, this.get(property.path) );
}else{
document[property.path] = this.get(property.path);
}
}
}
return document;
};
}

function getter_helper(prop){
return function(){
return this.get(prop);
};
return function(){
return this.get(prop);
};
}

function setter_helper(prop){
return function(value){
return this.set(prop, value);
};
return function(value){
return this.set(prop, value);
};
}


module.exports = exports = function fieldsAliasPlugin(schema, options) {
for(var path in schema.paths){
/*Set alias name only if alias property is setted in schema*/
if( schema.paths[path].options.alias && 'string' == typeof schema.paths[path].options.alias && schema.paths[path].options.alias !== ''){
var aliased_property = schema.paths[path].options.alias;
var real_property = schema.paths[path].path;
//Adding getters and setters for virtual alias names
schema
.virtual(aliased_property)
.get(getter_helper(real_property))
.set(setter_helper(real_property));
}
}
/*Adding method toAliasedFieldsObject to schema*/
schema.methods.toAliasedFieldsObject = _toAliasedFieldsObjectProvider(schema);
for(var path in schema.paths){
/*Set alias name only if alias property is setted in schema*/
if( schema.paths[path].options.alias && 'string' == typeof schema.paths[path].options.alias && schema.paths[path].options.alias !== ''){
var aliased_property = schema.paths[path].options.alias;
var real_property = schema.paths[path].path;
//Adding getters and setters for virtual alias names
schema
.virtual(aliased_property)
.get(getter_helper(real_property))
.set(setter_helper(real_property));
}
}
/*Adding method toAliasedFieldsObject to schema*/
schema.methods.toAliasedFieldsObject = _toAliasedFieldsObjectProvider(schema);
};

0 comments on commit d7fcd7b

Please sign in to comment.