1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-10-06 07:25:13 +01:00
HackMyResume/src/verbs/peek.js

73 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
Implementation of the 'peek' verb for HackMyResume.
2016-01-18 02:46:58 +00:00
@module verbs/peek
@license MIT. See LICENSE.md for details.
*/
(function(){
var Verb = require('../verbs/verb')
, _ = require('underscore')
, __ = require('lodash')
, safeLoadJSON = require('../utils/safe-json-loader')
, HMSTATUS = require('../core/status-codes')
, HMEVENT = require('../core/event-codes');
var PeekVerb = module.exports = Verb.extend({
init: function() {
this._super('peek');
},
invoke: function() {
2016-01-18 05:34:57 +00:00
this.stat( HMEVENT.begin, { cmd: 'peek' } );
peek.apply( this, arguments );
2016-01-18 05:34:57 +00:00
this.stat( HMEVENT.end );
}
});
/**
Peek at a resume, resume section, or resume field.
*/
function peek( src, dst, opts ) {
if(!src || !src.length) throw {fluenterror: HMSTATUS.resumeNotFound};
var objPath = (dst && dst[0]) || '';
_.each( src, function( t ) {
var obj = safeLoadJSON( t );
2016-01-18 23:35:38 +00:00
this.stat( HMEVENT.beforePeek, { file: t, target: objPath, isError: obj.ex } );
if( obj.ex ) {
2016-01-18 23:35:38 +00:00
if( obj.ex.operation === 'parse' )
this.err( HMSTATUS.parseError, obj.ex );
else {
obj.ex.quiet = true;
this.err( HMSTATUS.readError, obj.ex );
}
return;
}
2016-01-18 23:35:38 +00:00
var targ = objPath ? __.get( obj.json, objPath ) : obj.json;
this.stat( HMEVENT.afterPeek, { file: t, requested: objPath, target: targ } );
2016-01-18 23:35:38 +00:00
}, this);
}
}());