logstash: use {name=; value='} attrsets for repeated name-value pairs instead of parallel lists

This commit is contained in:
Shea Levy 2012-07-11 11:59:00 -04:00
parent 3039caf5ad
commit 315087def1
1 changed files with 13 additions and 13 deletions

View File

@ -17,7 +17,7 @@ let
(concatStringsSep ", " (map attrNameToConfigList (attrNames attrs))) + (concatStringsSep ", " (map attrNameToConfigList (attrNames attrs))) +
" ]"; " ]";
valueToConfig = name: value: valueToConfig = nvpair: let name = nvpair.name; value = nvpair.value; in
if (isAttrs value) && ((!(value ? __type)) || value.__type == "repeated") if (isAttrs value) && ((!(value ? __type)) || value.__type == "repeated")
then '' then ''
${name} { ${name} {
@ -26,12 +26,15 @@ let
'' ''
else "${name} => ${exprToConfig value}"; else "${name} => ${exprToConfig value}";
repeatedAttrsToConfig = names: values: repeatedAttrsToConfig = values:
concatStringsSep "\n" (zipListsWith valueToConfig names values); concatStringsSep "\n" (map valueToConfig values);
attrsToConfig = attrs: attrsToConfig = attrs:
let let
attrToConfig = name: valueToConfig name (getAttr name attrs); attrToConfig = name: valueToConfig {
inherit name;
value = (getAttr name attrs);
};
in in
concatStringsSep "\n" (map attrToConfig (attrNames attrs)); concatStringsSep "\n" (map attrToConfig (attrNames attrs));
@ -51,7 +54,7 @@ let
if isFloat expr then expr.value else if isFloat expr then expr.value else
if isList expr then listToConfig expr else if isList expr then listToConfig expr else
if isHash expr then hashToConfig expr.value else if isHash expr then hashToConfig expr.value else
if isRepeatedAttrs expr then repeatedAttrsToConfig expr.names expr.values if isRepeatedAttrs expr then repeatedAttrsToConfig expr.values
else attrsToConfig expr; else attrsToConfig expr;
mergeConfigs = configs: mergeConfigs = configs:
@ -60,14 +63,11 @@ let
let let
isRepeated = newAttrs ? __type && newAttrs.__type == "repeated"; isRepeated = newAttrs ? __type && newAttrs.__type == "repeated";
in { in {
names = attrs.names ++ values = attrs.values ++ (if isRepeated then newAttrs.values else
(if isRepeated then newAttrs.names else attrNames newAttrs); map (name: { inherit name; value = getAttr name newAttrs; })
(attrNames newAttrs));
values = attrs.values ++
(if isRepeated then newAttrs.values else attrValues newAttrs);
}; };
in (foldl op { names = []; values = []; } configs) // in (foldl op { values = []; } configs) // { __type = "repeated"; };
{ __type = "repeated"; };
in in
@ -92,7 +92,7 @@ in
and names are strings that can be repeated. name-value pairs with no and names are strings that can be repeated. name-value pairs with no
repeats are represented by attr sets. name-value pairs with repeats repeats are represented by attr sets. name-value pairs with repeats
are represented by an attrset with attr "__type" = "repeated" and are represented by an attrset with attr "__type" = "repeated" and
attrs "names" and "values" as matching lists pairing name and value. attr "values" as a list of {name; value;} attrsets.
bools, strings, ints, and arrays are mapped directly. Floats are bools, strings, ints, and arrays are mapped directly. Floats are
represented as an attrset with attr "__type" = "float" and attr value represented as an attrset with attr "__type" = "float" and attr value
set to the string representation of the float. Hashes are represented set to the string representation of the float. Hashes are represented