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:
63
src/verbs/peek.js
Normal file
63
src/verbs/peek.js
Normal 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 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
Reference in New Issue
Block a user