Update modelbaseclass api docs

This commit is contained in:
Loay 2017-05-03 11:10:31 -04:00
parent 6b43378396
commit 84b55d8160
1 changed files with 32 additions and 1 deletions

View File

@ -45,6 +45,8 @@ var BASE_TYPES = {
*
* @class
* @param {Object} data Initial object data
* @param {Object} options An object to control the instantiation
* @returns {ModelBaseClass} an instance of the ModelBaseClass
*/
function ModelBaseClass(data, options) {
options = options || {};
@ -71,7 +73,7 @@ function ModelBaseClass(data, options) {
ModelBaseClass.prototype._initProperties = function(data, options) {
var self = this;
var ctor = this.constructor;
// issue#1261
if (typeof data !== 'undefined' && data.constructor &&
typeof (data.constructor) !== 'function') {
throw new Error(g.f('Property name "{{constructor}}" is not allowed in %s data', ctor.modelName));
@ -371,6 +373,11 @@ ModelBaseClass.defineProperty = function(prop, params) {
}
};
/**
* Get model property type.
* @param {String} propName Property name
* @returns {String} Name of property type
*/
ModelBaseClass.getPropertyType = function(propName) {
var prop = this.definition.properties[propName];
if (!prop) {
@ -384,6 +391,11 @@ ModelBaseClass.getPropertyType = function(propName) {
return prop.type.name;
};
/**
* Get model property type.
* @param {String} propName Property name
* @returns {String} Name of property type
*/
ModelBaseClass.prototype.getPropertyType = function(propName) {
return this.constructor.getPropertyType(propName);
};
@ -401,6 +413,9 @@ ModelBaseClass.toString = function() {
* Returns a canonical object representation (no getters and setters).
*
* @param {Boolean} onlySchema Restrict properties to dataSource only. Default is false. If true, the function returns only properties defined in the schema; Otherwise it returns all enumerable properties.
* @param {Boolean} removeHidden Boolean flag as part of the transformation. If true, then hidden properties should not be brought out.
* @param {Boolean} removeProtected Boolean flag as part of the transformation. If true, then protected properties should not be brought out.
* @returns {Object} returns Plain JSON object
*/
ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removeProtected) {
if (onlySchema === undefined) {
@ -527,6 +542,11 @@ ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removePro
return data;
};
/**
* Checks if property is protected.
* @param {String} propertyName Property name
* @returns {Boolean} true or false if proptected or not.
*/
ModelBaseClass.isProtectedProperty = function(propertyName) {
var Model = this;
var settings = Model.definition && Model.definition.settings;
@ -546,6 +566,11 @@ ModelBaseClass.isProtectedProperty = function(propertyName) {
}
};
/**
* Checks if property is hidden.
* @param {String} propertyName Property name
* @returns {Boolean} true or false if hidden or not.
*/
ModelBaseClass.isHiddenProperty = function(propertyName) {
var Model = this;
var settings = Model.definition && Model.definition.settings;
@ -614,6 +639,12 @@ ModelBaseClass.prototype.inspect = function(depth) {
});
};
/**
*
* @param {String} anotherClass could be string or class. Name of the class or the class itself
* @param {Object} options An object to control the instantiation
* @returns {ModelClass}
*/
ModelBaseClass.mixin = function(anotherClass, options) {
if (typeof anotherClass === 'string') {
this.modelBuilder.mixins.applyMixin(this, anotherClass, options);