1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-13 04:50:09 +00:00
HackMyResume/dist/verbs/peek.js

107 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-01-27 10:29:26 +00:00
/**
Implementation of the 'peek' verb for HackMyResume.
@module verbs/peek
@license MIT. See LICENSE.md for details.
*/
(function() {
var HMEVENT, HMSTATUS, PeekVerb, Verb, _, __, _peek, _peekOne, safeLoadJSON,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
2016-01-27 10:29:26 +00:00
Verb = require('../verbs/verb');
_ = require('underscore');
__ = require('lodash');
safeLoadJSON = require('../utils/safe-json-loader');
HMSTATUS = require('../core/status-codes');
HMEVENT = require('../core/event-codes');
module.exports = PeekVerb = (function(superClass) {
extend(PeekVerb, superClass);
function PeekVerb() {
PeekVerb.__super__.constructor.call(this, 'peek', _peek);
2016-01-27 10:29:26 +00:00
}
return PeekVerb;
})(Verb);
2016-01-27 10:29:26 +00:00
/** Peek at a resume, resume section, or resume field. */
2016-01-27 10:29:26 +00:00
2016-02-02 02:14:36 +00:00
_peek = function(src, dst, opts) {
var objPath, results;
2016-01-27 10:29:26 +00:00
if (!src || !src.length) {
2016-02-02 02:14:36 +00:00
this.err(HMSTATUS.resumeNotFound, {
quit: true
2016-01-27 10:29:26 +00:00
});
2016-02-02 02:14:36 +00:00
return null;
2016-01-27 10:29:26 +00:00
}
objPath = (dst && dst[0]) || '';
2016-02-02 02:14:36 +00:00
results = _.map(src, function(t) {
var tgt;
if (opts.assert && this.hasError()) {
return {};
2016-01-27 10:29:26 +00:00
}
2016-02-02 02:14:36 +00:00
tgt = _peekOne.call(this, t, objPath);
2016-02-02 22:34:10 +00:00
if (tgt.error) {
2016-02-04 01:08:17 +00:00
this.setError(tgt.error.fluenterror, tgt.error);
2016-01-27 10:29:26 +00:00
}
2016-02-02 22:34:10 +00:00
return tgt;
2016-01-27 10:29:26 +00:00
}, this);
2016-02-02 02:14:36 +00:00
if (this.hasError() && !opts.assert) {
this.reject(this.errorCode);
} else if (!this.hasError()) {
this.resolve(results);
}
return results;
};
/** Peek at a single resume, resume section, or resume field. */
_peekOne = function(t, objPath) {
2016-02-02 22:34:10 +00:00
var errCode, obj, pkgError, tgt;
2016-02-02 02:14:36 +00:00
this.stat(HMEVENT.beforePeek, {
file: t,
target: objPath
});
obj = safeLoadJSON(t);
tgt = null;
if (!obj.ex) {
tgt = objPath ? __.get(obj.json, objPath) : obj.json;
}
2016-02-02 22:34:10 +00:00
pkgError = null;
2016-02-02 02:14:36 +00:00
if (obj.ex) {
errCode = obj.ex.op === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
2016-02-02 02:14:36 +00:00
if (errCode === HMSTATUS.readError) {
obj.ex.quiet = true;
}
2016-02-02 22:34:10 +00:00
pkgError = {
2016-02-02 02:14:36 +00:00
fluenterror: errCode,
inner: obj.ex
};
}
2016-02-02 22:34:10 +00:00
this.stat(HMEVENT.afterPeek, {
file: t,
requested: objPath,
target: obj.ex ? void 0 : tgt,
error: pkgError
});
return {
2016-02-04 01:08:17 +00:00
val: obj.ex ? void 0 : tgt,
error: pkgError
2016-02-02 22:34:10 +00:00
};
2016-01-27 10:29:26 +00:00
};
}).call(this);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=peek.js.map