'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) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _repository;

function _load_repository() {
  return _repository = _interopRequireDefault(require('./repository'));
}

var _object;

function _load_object() {
  return _object = _interopRequireDefault(require('./object'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Ref = function () {
  function Ref(hash) {
    _classCallCheck(this, Ref);

    if (!hash) throw new Error('failed creating a Ref object, the hash argument is empty');
    this.hash = hash;
  }

  _createClass(Ref, [{
    key: 'toString',
    value: function toString() {
      return this.hash;
    }
  }, {
    key: 'load',
    value: function load(repository) {
      return repository.findOne(this);
    }
  }, {
    key: 'loadSync',
    value: function loadSync(repo) {
      var throws = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;

      return repo.loadSync(this, throws);
    }
  }, {
    key: 'loadRaw',
    value: function loadRaw(repo) {
      return repo.loadRaw(this);
    }
  }], [{
    key: 'from',
    value: function from(hash) {
      return new Ref(hash);
    }
  }]);

  return Ref;
}();

exports.default = Ref;