Skip to content
This repository has been archived by the owner on Oct 27, 2019. It is now read-only.

Commit

Permalink
ensure that all child hooks get normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
subtleGradient committed Apr 13, 2012
1 parent 7a8088d commit 3add87f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/herd.js
Expand Up @@ -16,7 +16,7 @@ function Herd(config){
Hook.call(herd, herd.configFrom(config))

if (!(herd.childHooks && Array.isArray(herd.childHooks))) herd.childHooks = []
herd.childHooks = herd.childHooks.map(herd.configFrom, herd)
herd.childHooks = herd.childHooks.map(herd.childConfigFrom, herd)

herd.on('hook::ready', function(){
herd.listening = true // workaround hook.io bug
Expand Down Expand Up @@ -45,6 +45,8 @@ Herd.prototype.ignoreSTDIN = true
// array of child hook configs
Herd.prototype.childHooks = null

Herd.prototype.childConfigDefaults = {
}
Herd.prototype.normalizeConfigSrc = function(config, module){
if (config.type) {
config.src = 'hook.io-' + config.type
Expand All @@ -55,6 +57,20 @@ Herd.prototype.normalizeConfigSrc = function(config, module){
}
return config
}

Herd.prototype.childConfigFrom = function(childConfig){
childConfig = this.configFrom(childConfig)

for (var key in this.childConfigDefaults) {
if (childConfig.hasOwnProperty(key)) continue
childConfig[key] = this.childConfigDefaults[key]
}

var parentModule = this.configFilePath ? requireModule(this.configFilePath) : childConfig.parentModule
this.normalizeConfigSrc(childConfig, parentModule)

return childConfig
}

Herd.prototype.configFrom = function(config){
if (!config.configFilePath) return config
Expand Down

0 comments on commit 3add87f

Please sign in to comment.