all files / src/ Base.js

92.11% Statements 35/38
76.47% Branches 13/17
100% Functions 10/10
95.45% Lines 21/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83            85×                     85×   85×   85×       85× 85×   85× 37×     48× 48×                                               307×                     164×          
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
var Base = function () {
  /**
   * Base constructor
   * @constructor Base
   * @param  {RBAC}     rbac     Instance of the RBAC
   * @param  {String}   name     Name of the grant
   * @param  {Boolean}  add      True if you need to save it to storage
   * @param  {Function} cb       Callback function after add
   */
 
  function Base(rbac, name, add, cb) {
    var _this = this;
 
    _classCallCheck(this, Base);
 
    Iif (!rbac || !name || typeof cb !== 'function') {
      return cb(new Error('One of parameters is undefined'));
    }
 
    this._name = name;
    this._rbac = rbac;
 
    if (!add) {
      return cb(null, this);
    }
 
    rbac.add(this, function (err) {
      return cb(err, _this);
    });
  }
 
  /**
   * Get name of actual instance
   * @member Base#name {String}
   */
 
 
  _createClass(Base, [{
    key: 'remove',
 
 
    /**
     * Remove this from RBAC (storage)
     * @method Base#remove
     * @param  {Function} cb Callback function
     * @return {Base}
     */
    value: function remove(cb) {
      this.rbac.remove(this, cb);
      return this;
    }
  }, {
    key: 'name',
    get: function get() {
      return this._name;
    }
 
    /**
     * Get instance of RBAC
     * @member Base#rbac {RBAC|null} Instance of RBAC
     */
 
  }, {
    key: 'rbac',
    get: function get() {
      return this._rbac;
    }
  }]);
 
  return Base;
}();
 
exports.default = Base;