From 4c1adf258bb5097398d703827b8927f74288a8c5 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 29 Dec 2017 08:08:04 -0500 Subject: [PATCH] refactor: add method to get directly property --- lib/core/config.js | 13 ++++--------- lib/core/plugins.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index c1aeaa85..44cecab1 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -74,7 +74,6 @@ Config.prototype.loadBlockchainConfigFile = function() { }; Config.prototype.loadContractsConfigFile = function() { - var configObject = { "default": { "versions": { @@ -96,14 +95,10 @@ Config.prototype.loadContractsConfigFile = function() { } }; - var configPlugins = this.plugins.getPluginsFor('contractsConfig'); - if (configPlugins.length > 0) { - configPlugins.forEach(function(plugin) { - plugin.contractsConfigs.forEach(function(pluginConfig) { - configObject = utils.recursiveMerge(configObject, pluginConfig); - }); - }); - } + var contractsConfigs = this.plugins.getPluginsProperty('contractsConfig', 'contractsConfigs'); + contractsConfigs.forEach(function(pluginConfig) { + configObject = utils.recursiveMerge(configObject, pluginConfig); + }); var contractsConfig; if (fs.existsSync(this.configDir + "contracts.json")) { diff --git a/lib/core/plugins.js b/lib/core/plugins.js index d2ba61b8..3ac88052 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -51,4 +51,14 @@ Plugins.prototype.getPluginsFor = function(pluginType) { }); }; +Plugins.prototype.getPluginsProperty = function(pluginType, property) { + let matchingPlugins = this.plugins.filter(function(plugin) { + return plugin.has(pluginType); + }); + + return matchingPlugins.map((plugin) => { + return plugin[property]; + }); +}; + module.exports = Plugins;