1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Compare facts in both directions, not just one way

This commit is contained in:
Joe Fiorini 2015-06-02 13:06:30 -04:00
parent 0dd9c4e5eb
commit a9a839a549
2 changed files with 11 additions and 5 deletions

View File

@ -11,6 +11,15 @@ export function compareFacts(module, facts) {
if (module.displayType === 'nested') {
return compareNestedFacts(facts);
} else {
return compareFlatFacts(facts, module.nameKey, module.compareKey, module.factTemplate);
// For flat structures we compare left-to-right, then right-to-left to
// make sure we get a good comparison between both hosts
var compare = _.partialRight(compareFlatFacts, module.nameKey, module.compareKey, module.factTemplate);
var leftToRight = compare(facts[0], facts[1]);
var rightToLeft = compare(facts[1], facts[0]);
return _(leftToRight)
.concat(rightToLeft)
.unique('displayKeyPath')
.value();
}
}

View File

@ -38,10 +38,7 @@ function slotFactValues(basisPosition, basisValue, comparatorValue) {
}
export default
function flatCompare(facts, nameKey, compareKeys, factTemplate) {
var comparatorFacts = facts[0];
var basisFacts = facts[1];
function flatCompare(basisFacts, comparatorFacts, nameKey, compareKeys, factTemplate) {
return basisFacts.reduce(function(arr, basisFact) {
var searcher = {};