All files / piscosour/lib context.js

26.67% Statements 4/15
0% Branches 0/6
0% Functions 0/2
26.67% Lines 4/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33    1x 1x   1x                                                   1x  
'use strict';
 
const config = require('./config');
const logger = require('./logger');
 
const context = {
 
  cis: function(name, noCache) {
    const ctx = config.get().contexts[name];
 
    if (!ctx) {
      return false;
    }
 
    return require(ctx._module).check(noCache);
  },
 
  whoami: function(noCache) {
    const ami = [];
    for (const name in config.get().contexts) { //eslint-disable-line guard-for-in
      const cis = context.cis(name, noCache);
      logger.trace('checking if you are in a', '#bold', name, '-->', cis ? '#green' : '#red', cis);
      if (cis) {
        ami.push(name);
      }
    }
    return ami;
  }
 
};
 
module.exports = context;