Merge pull request #82 from mrvini/master

updates to defaults entities, making sure that node-ipc could be run …
This commit is contained in:
Brandon Nozaki Miller 2016-08-02 12:14:56 -07:00 committed by GitHub
commit 56dfe7f0ea
2 changed files with 43 additions and 5 deletions

3
.npmignore Normal file
View file

@ -0,0 +1,3 @@
.tags
tags
spec

View file

@ -1,12 +1,25 @@
'use strict'; 'use strict';
/*eslint no-magic-numbers: ["error", { "ignore": [ 0] }]*/
/**
* @module entities
*/
const os = require('os'); const os = require('os');
/**
* @class Defaults
* @description Defaults Entity
*/
class Defaults{ class Defaults{
/**
* @constructor
* @method constructor
* @return {void}
*/
constructor(){ constructor(){
const IPType=os.networkInterfaces()[
Object.keys(os.networkInterfaces())[0]
][0].family;
Object.defineProperties( Object.defineProperties(
this, this,
@ -24,7 +37,7 @@ class Defaults{
networkHost : { networkHost : {
enumerable:true, enumerable:true,
writable:true, writable:true,
value:(IPType=='IPv6')? '::1' : '127.0.0.1' value: ''
}, },
networkPort : { networkPort : {
enumerable:true, enumerable:true,
@ -89,7 +102,7 @@ class Defaults{
IPType : { IPType : {
enumerable:true, enumerable:true,
writable:true, writable:true,
value:IPType value: getIPType()
}, },
tls : { tls : {
enumerable:true, enumerable:true,
@ -98,7 +111,29 @@ class Defaults{
} }
} }
); );
this.networkHost = (this.IPType == 'IPv6') ? '::1' : '127.0.0.1';
} }
} }
/**
* method to get ip type
*
* @method getIPType
* @return {string} ip type
*/
function getIPType() {
const networkInterfaces = os.networkInterfaces();
let IPType = '';
if (networkInterfaces
&& Array.isArray(networkInterfaces)
&& networkInterfaces.length > 0) {
// getting the family of first network interface available
IPType = networkInterfaces [
Object.keys( networkInterfaces )[0]
][0].family;
}
return IPType;
}
module.exports=Defaults; module.exports=Defaults;