Source: models/Dir.js

  1. var assign = require('object-assign');
  2. var Node = require('./Node');
  3. /**
  4. * Creates a new Dir reference, based on output from the `p4 dirs` command.
  5. *
  6. * @param {object} obj Initialize the instance with data from the server (typical)
  7. * @constructor
  8. * @memberOf models
  9. */
  10. function Dir(obj) {
  11. this._data = obj || {};
  12. /**
  13. * The immediate directories and files under this directory.
  14. *
  15. * @type {Array<PathItem>}
  16. */
  17. this.children = [];
  18. var self = this;
  19. Object.defineProperties(this, {
  20. /**
  21. * The directory path in the server.
  22. *
  23. * @type string
  24. * @name models.Dir#dir
  25. * @memberOf models.Dir
  26. * @readonly
  27. */
  28. 'dir': {
  29. get: function() {
  30. return self._data['Dir'];
  31. }
  32. },
  33. /**
  34. * For consistency with Node operations
  35. *
  36. * @type string
  37. * @name models.Dir#name
  38. * @memberOf models.Dir
  39. * @readonly
  40. */
  41. 'name': {
  42. get: function() {
  43. return this.pathId[this.pathId.length - 1];
  44. }
  45. },
  46. /**
  47. * For consistency with Node operations
  48. *
  49. * @type Array<string>
  50. * @name models.Dir#pathId
  51. * @memberOf models.Dir
  52. * @readonly
  53. */
  54. 'pathId': {
  55. get: function() {
  56. var path = this.dir;
  57. if (path.startsWith('//')) {
  58. path = path.substring(2);
  59. }
  60. return path.split('/');
  61. }
  62. }
  63. });
  64. }
  65. assign(Dir.prototype, Node, {
  66. });
  67. module.exports = Dir;