1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-10 07:47:07 +01:00

Introduce PEEK command.

Peek at arbitrary resumes and resume objects paths with "hackmyresume
peek <resume> [objectPath]". For ex:

hackmyresume PEEK resume.json
hackmyresume PEEK resume.json info
hackmyresume PEEK resume.json employment[2].keywords
hackmyresume PEEK r1.json r2.json r3.json info.brief
This commit is contained in:
hacksalot
2016-01-15 13:08:01 -05:00
parent de5c2ecb95
commit 4c5ccc001a
7 changed files with 125 additions and 10 deletions

63
src/verbs/peek.js Normal file
View File

@ -0,0 +1,63 @@
/**
Implementation of the 'peek' verb for HackMyResume.
@module peek.js
@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() {
peek.apply( this, arguments );
}
});
/**
Peek at a resume, resume section, or resume field.
*/
function peek( src, dst, opts ) {
if(!src || !src.length) throw {fluenterror: HMSTATUS.resumeNotFound};
this.stat( HMEVENT.begin );
var objPath = (dst && dst[0]) || '';
_.each( src, function( t ) {
this.stat( HMEVENT.beforePeek, { file: t, target: objPath } );
var obj = safeLoadJSON( t );
if( obj.ex ) {
this.err( obj.ex.fluenterror, obj.ex );
}
var targ = objPath ? __.get( obj.json, objPath ) : obj;
this.stat( HMEVENT.afterPeek, { file: t, requested: objPath, target: targ } );
}, this);
this.stat( HMEVENT.end );
}
}());