src/back/models/attributes/AttributeDictionary.js
function _addAttribute() {
  var attributeDictionary = arguments[0];

  var attribute = null;
  var name = null;

  if (arguments.length === 2) {
    attribute = arguments[1];
  } else {
    attribute = arguments[1];
    name = arguments[2];
  }

  expect(attribute).to.be.an(
    'object',
    'Invalid argument type when adding an attribute ' + (name ? 'called "' +
    name + '" ' : '') + 'in an AttributeDictionary (it has to be an object)'
  );

  if (name) {
    if (attribute.name) {
      expect(attribute.name).to.equal(
        name,
        'Invalid argument "name" when adding an attribute called "' +
        attribute.name + '" in an AttributeDictionary (the name given in ' +
        'argument and the name given in the attribute object should be equal)'
      );
    } else {
      attribute.name = name;
    }
  }

  if (!(attribute instanceof Attribute)) {
    attribute = Attribute.resolve(attribute);
  }

  expect(attribute.constructor).to.not.equal(
    Attribute,
    'Invalid attribute "' + attribute.name + '". Attribute is an abstract ' +
    'class and cannot be directly instantiated and added in an ' +
    'AttributeDictionary'
  );

  expect(attributeDictionary).to.not.have.ownProperty(
    attribute.name,
    'Duplicated attribute name "' + attribute.name + '"'
  );

  Object.defineProperty(attributeDictionary, attribute.name, {
    value: attribute,
    enumerable: true,
    writable: false,
    configurable: false
  });
}
function _addAttribute() {
  var attributeDictionary = arguments[0];

  var attribute = null;
  var name = null;

  if (arguments.length === 2) {
    attribute = arguments[1];
  } else {
    attribute = arguments[1];
    name = arguments[2];
  }

  expect(attribute).to.be.an(
    'object',
    'Invalid argument type when adding an attribute ' + (name ? 'called "' +
    name + '" ' : '') + 'in an AttributeDictionary (it has to be an object)'
  );

  if (name) {
    if (attribute.name) {
      expect(attribute.name).to.equal(
        name,
        'Invalid argument "name" when adding an attribute called "' +
        attribute.name + '" in an AttributeDictionary (the name given in ' +
        'argument and the name given in the attribute object should be equal)'
      );
    } else {
      attribute.name = name;
    }
  }

  if (!(attribute instanceof Attribute)) {
    attribute = Attribute.resolve(attribute);
  }

  expect(attribute.constructor).to.not.equal(
    Attribute,
    'Invalid attribute "' + attribute.name + '". Attribute is an abstract ' +
    'class and cannot be directly instantiated and added in an ' +
    'AttributeDictionary'
  );

  expect(attributeDictionary).to.not.have.ownProperty(
    attribute.name,
    'Duplicated attribute name "' + attribute.name + '"'
  );

  Object.defineProperty(attributeDictionary, attribute.name, {
    value: attribute,
    enumerable: true,
    writable: false,
    configurable: false
  });
}
function _addAttribute ( ) { var attributeDictionary = arguments [ 0 ] ; var attribute = null ; var name = null ; if ( arguments . length === 2 ) { attribute = arguments [ 1 ] ; } else { attribute = arguments [ 1 ] ; name = arguments [ 2 ] ; } expect ( attribute ) . to . be . an ( 'object' , 'Invalid argument type when adding an attribute ' + ( name ? 'called "' + name + '" ' : '' ) + 'in an AttributeDictionary (it has to be an object)' ) ; if ( name ) { if ( attribute . name ) { expect ( attribute . name ) . to . equal ( name , 'Invalid argument "name" when adding an attribute called "' + attribute . name + '" in an AttributeDictionary (the name given in ' + 'argument and the name given in the attribute object should be equal)' ) ; } else { attribute . name = name ; } } if ( ! ( attribute instanceof Attribute ) ) { attribute = Attribute . resolve ( attribute ) ; } expect ( attribute . constructor ) . to . not . equal ( Attribute , 'Invalid attribute "' + attribute . name + '". Attribute is an abstract ' + 'class and cannot be directly instantiated and added in an ' + 'AttributeDictionary' ) ; expect ( attributeDictionary ) . to . not . have . ownProperty ( attribute . name , 'Duplicated attribute name "' + attribute . name + '"' ) ; Object . defineProperty ( attributeDictionary , attribute . name , { value : attribute , enumerable : true , writable : false , configurable : false } ) ; }
Adds a new attribute to the dictionary.
@name
module:back4app-entity/models/attributes.AttributeDictionary~_addAttribute
@function
@param {!module:back4app-entity/models/attributes.AttributeDictionary}
attributeDictionary It is the attribute dictionary to which the attribute
will be added.
@param {!module:back4app-entity/models/attributes.Attribute} attribute This
is the attribute to be added. It can be passed as a
{@link module:back4app-entity/models/attributes.Attribute} instance.
@param {?string} [name] This is the name of the attribute.
@private
@example
var attributeDictionary = new AttributeDictionary();
_addAttribute(
attributeDictionary,
new StringAttribute('attribute'),
'attribute'
);
 
Adds a new attribute to the dictionary.
@name
module:back4app-entity/models/attributes.AttributeDictionary~_addAttribute
@function
@param {!module:back4app-entity/models/attributes.AttributeDictionary}
attributeDictionary It is the attribute dictionary to which the attribute
will be added.
@param {!Object} attribute This is the attribute to be added. It can be
passed as an Object, as specified in
{@link module:back4app-entity/models/attributes.Attribute}.
@param {!string} [attribute.name] It is the name of the attribute. It is
optional if it is passed as an argument in the function.
@param {!string} [attribute.type='Object'] It is the type of the attribute.
It is optional and if not passed it will assume 'Object' as the default
value.
@param {!string} [attribute.multiplicity='1'] It is the multiplicity of the
attribute. It is optional and if not passed it will assume '1' as the default
value.
@param {?(boolean|number|string|Object|function)} [attribute.default] It is
the default expression of the attribute.
@param {?string} [name] This is the name of the attribute.
@private
@example
var attributeDictionary = new AttributeDictionary();
_addAttribute(attributeDictionary, {}, 'attribute');
Adds a new attribute to the dictionary .