Source: models/Dir.js

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

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

/**
 * Creates a new Dir reference, based on output from the `p4 dirs` command.
 *
 * @param {object} obj Initialize the instance with data from the server (typical)
 * @constructor
 * @memberOf models
 */
function Dir(obj) {
  this._data = obj || {};

  /**
   * The immediate directories and files under this directory.
   *
   * @type {Array<PathItem>}
   */
  this.children = [];

  var self = this;

  Object.defineProperties(this, {
    /**
     * The directory path in the server.
     *
     * @type string
     * @name models.Dir#dir
     * @memberOf models.Dir
     * @readonly
     */
    'dir': {
      get: function() {
        return self._data['Dir'];
      }
    },
    /**
     * For consistency with Node operations
     *
     * @type string
     * @name models.Dir#name
     * @memberOf models.Dir
     * @readonly
     */
    'name': {
      get: function() {
        return this.pathId[this.pathId.length - 1];
      }
    },
    /**
     * For consistency with Node operations
     *
     * @type Array<string>
     * @name models.Dir#pathId
     * @memberOf models.Dir
     * @readonly
     */
    'pathId': {
      get: function() {
        var path = this.dir;
        if (path.startsWith('//')) {
          path = path.substring(2);
        }
        return path.split('/');
      }
    }
  });
}

assign(Dir.prototype, Node, {

});

module.exports = Dir;