Source: models/File.js

var assign = require('object-assign');

var Node = require('./Node');
require('../polyfill');

/**
 * Create a file from the server's object representation.
 *
 * @param {Object} obj Data from the server, which doesn't follow typical
 *                     javaScript naming conventions.
 * @constructor
 * @memberof models
 */
function File(obj) {
  this._data = obj || {};

  var self = this;

  Object.defineProperties(this, {
    /**
     * The absolute depot path of the file
     *
     * @type string
     * @name models.File#depotFile
     * @memberOf models.File
     */
    'depotFile': {
      get: function() {
        return self._data['DepotFile'];
      },
      set: function(x) {
        self._data['DepotFile'] = x;
      }
    },
    /**
     * File's revision number.
     *
     * @type number
     * @name models.File#revision
     * @memberOf models.File
     * @readonly
     */
    'revision': {
      get: function() {
        var n = self._data['Revision'];
        if (typeof n == 'string') {
          n = parseInt(n);
        }
        return n;
      }
    },
    /**
     * ID of the changelist that created this file revision.
     *
     * @type string
     * @name models.File#change
     * @memberOf models.File
     * @readonly
     */
    'change': {
      get: function() {
        return self._data['Change'];
      }
    },
    /**
     * Action taken at the head, one of 'add', 'edit', 'delete', 'branch',
     * 'move_add', 'move_delete', 'integrate', 'import', 'purge', or 'archive'.
     *
     * @type string
     * @name models.File#action
     * @memberOf models.File
     * @readonly
     */
    'action': {
      get: function() {
        return self._data['Action'];
      }
    },
    /**
     * File type - one of 'text', 'binary', 'symlink', 'apple', 'resource',
     * 'unicode', 'utf16'
     *
     * @type string
     * @name models.File#type
     * @memberOf models.File
     * @readonly
     */
    'type': {
      get: function() {
        return self._data['Type'];
      }
    },
    /**
     * Date of when the file revision was created
     *
     * @type Date
     * @name models.File#date
     * @memberOf models.File
     * @readonly
     */
    'date': {
      get: function() {
        return new Date(self._data['Date']);
      }
    },
    /**
     * For consistency with Node operations
     *
     * @type string
     * @name models.File#name
     * @memberOf models.File
     * @readonly
     */
    'name': {
      get: function() {
        return this.pathId[this.pathId.length - 1];
      }
    },
    /**
     * For consistency with Node operations
     *
     * @type Array<string>
     * @name models.File#pathId
     * @memberOf models.File
     * @readonly
     */
    'pathId': {
      get: function() {
        var path = this.depotFile;
        if (path.startsWith('//')) {
          path = path.substring(2);
        }
        return path.split('/');
      }
    }
  });
}

assign(File.prototype, Node, {

});

module.exports = File;