Skip to content

Commit

Permalink
Add match context for implementors
Browse files Browse the repository at this point in the history
  • Loading branch information
davedoesdev committed Aug 4, 2017
1 parent 60554ad commit 2e84270
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 45 deletions.
2 changes: 1 addition & 1 deletion coverage/lcov-report/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Jul 31 2017 22:26:44 GMT+0100 (BST)
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Fri Aug 04 2017 08:43:10 GMT+0100 (BST)
</div>
</div>
<script src="prettify.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion coverage/lcov-report/qlobber/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Jul 31 2017 22:26:44 GMT+0100 (BST)
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Fri Aug 04 2017 08:43:10 GMT+0100 (BST)
</div>
</div>
<script src="../prettify.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion coverage/lcov-report/qlobber/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Jul 31 2017 22:26:44 GMT+0100 (BST)
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Fri Aug 04 2017 08:43:10 GMT+0100 (BST)
</div>
</div>
<script src="../prettify.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion coverage/lcov-report/qlobber/lib/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Jul 31 2017 22:26:44 GMT+0100 (BST)
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Fri Aug 04 2017 08:43:10 GMT+0100 (BST)
</div>
</div>
<script src="../../prettify.js"></script>
Expand Down
38 changes: 19 additions & 19 deletions coverage/lcov-report/qlobber/lib/qlobber.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ <h1>
return r;
};
&nbsp;
Qlobber.prototype._match_some = function (v, i, words, st)
Qlobber.prototype._match_some = function (v, i, words, st, ctx)
{
var j, w;
&nbsp;
Expand All @@ -1569,7 +1569,7 @@ <h1>
{
for (j = i; j &lt; words.length; j += 1)
{
v = this._match(v, j, words, st);
v = this._match(v, j, words, st, ctx);
}
break;
}
Expand All @@ -1578,7 +1578,7 @@ <h1>
return v;
};
&nbsp;
Qlobber.prototype._match = function (v, i, words, sub_trie)
Qlobber.prototype._match = function (v, i, words, sub_trie, ctx)
{
var word, st;
&nbsp;
Expand All @@ -1587,9 +1587,9 @@ <h1>
if (st)
{
// in the common case there will be no more levels...
v = this._match_some(v, i, words, st);
v = this._match_some(v, i, words, st, ctx);
// and we'll end up matching the rest of the words:
v = this._match(v, words.length, words, st);
v = this._match(v, words.length, words, st, ctx);
}
&nbsp;
if (i === words.length)
Expand All @@ -1600,8 +1600,8 @@ <h1>
{
if (v.dest)
{
this._add_values(v.dest, v.source);
this._add_values(v.dest, st);
this._add_values(v.dest, v.source, ctx);
this._add_values(v.dest, st, ctx);
v = v.dest;
}
else if (v.source)
Expand All @@ -1611,7 +1611,7 @@ <h1>
}
else
{
this._add_values(v, st);
this._add_values(v, st, ctx);
}
}
}
Expand All @@ -1625,7 +1625,7 @@ <h1>
&nbsp;
if (st)
{
v = this._match(v, i + 1, words, st);
v = this._match(v, i + 1, words, st, ctx);
}
}
&nbsp;
Expand All @@ -1635,20 +1635,20 @@ <h1>
&nbsp;
if (st)
{
v = this._match(v, i + 1, words, st);
v = this._match(v, i + 1, words, st, ctx);
}
}
}
&nbsp;
return v;
};
&nbsp;
Qlobber.prototype._match2 = function (v, topic)
Qlobber.prototype._match2 = function (v, topic, ctx)
{
var vals = this._match(
{
source: v
}, 0, topic.split(this._separator), this._trie);
}, 0, topic.split(this._separator), this._trie, ctx);
&nbsp;
return vals.source || vals;
};
Expand Down Expand Up @@ -1778,9 +1778,9 @@ <h1>
@param {String} topic The topic to match against.
@return {Array} List of values that matched the topic. This may contain duplicates.
*/
Qlobber.prototype.match = function (topic)
Qlobber.prototype.match = function (topic, ctx)
{
return this._match2([], topic);
return this._match2([], topic, ctx);
};
&nbsp;
/**
Expand Down Expand Up @@ -1892,9 +1892,9 @@ <h1>
@param {String} topic The topic to match against.
@return {Set} [ES6 Set](http://www.ecma-international.org/ecma-262/6.0/#sec-set-objects) of values that matched the topic.
*/
QlobberDedup.prototype.match = function (topic)
QlobberDedup.prototype.match = function (topic, ctx)
{
return this._match2(new Set(), topic);
return this._match2(new Set(), topic, ctx);
};
&nbsp;
/**
Expand Down Expand Up @@ -1954,9 +1954,9 @@ <h1>
@param {String} topic The topic to match against.
@return {Boolean} Whether the `QlobberTrue` instance matches the topic.
*/
QlobberTrue.prototype.match = function (topic)
QlobberTrue.prototype.match = function (topic, ctx)
{
return this.test(topic);
return this.test(topic, ctx);
};
&nbsp;
exports.Qlobber = Qlobber;
Expand All @@ -1969,7 +1969,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Jul 31 2017 22:26:44 GMT+0100 (BST)
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Fri Aug 04 2017 08:43:10 GMT+0100 (BST)
</div>
</div>
<script src="../../prettify.js"></script>
Expand Down
36 changes: 18 additions & 18 deletions lib/qlobber.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Qlobber.prototype._remove = function (val, i, words, sub_trie)
return r;
};

Qlobber.prototype._match_some = function (v, i, words, st)
Qlobber.prototype._match_some = function (v, i, words, st, ctx)
{
var j, w;

Expand All @@ -244,7 +244,7 @@ Qlobber.prototype._match_some = function (v, i, words, st)
{
for (j = i; j < words.length; j += 1)
{
v = this._match(v, j, words, st);
v = this._match(v, j, words, st, ctx);
}
break;
}
Expand All @@ -253,7 +253,7 @@ Qlobber.prototype._match_some = function (v, i, words, st)
return v;
};

Qlobber.prototype._match = function (v, i, words, sub_trie)
Qlobber.prototype._match = function (v, i, words, sub_trie, ctx)
{
var word, st;

Expand All @@ -262,9 +262,9 @@ Qlobber.prototype._match = function (v, i, words, sub_trie)
if (st)
{
// in the common case there will be no more levels...
v = this._match_some(v, i, words, st);
v = this._match_some(v, i, words, st, ctx);
// and we'll end up matching the rest of the words:
v = this._match(v, words.length, words, st);
v = this._match(v, words.length, words, st, ctx);
}

if (i === words.length)
Expand All @@ -275,8 +275,8 @@ Qlobber.prototype._match = function (v, i, words, sub_trie)
{
if (v.dest)
{
this._add_values(v.dest, v.source);
this._add_values(v.dest, st);
this._add_values(v.dest, v.source, ctx);
this._add_values(v.dest, st, ctx);
v = v.dest;
}
else if (v.source)
Expand All @@ -286,7 +286,7 @@ Qlobber.prototype._match = function (v, i, words, sub_trie)
}
else
{
this._add_values(v, st);
this._add_values(v, st, ctx);
}
}
}
Expand All @@ -300,7 +300,7 @@ Qlobber.prototype._match = function (v, i, words, sub_trie)

if (st)
{
v = this._match(v, i + 1, words, st);
v = this._match(v, i + 1, words, st, ctx);
}
}

Expand All @@ -310,20 +310,20 @@ Qlobber.prototype._match = function (v, i, words, sub_trie)

if (st)
{
v = this._match(v, i + 1, words, st);
v = this._match(v, i + 1, words, st, ctx);
}
}
}

return v;
};

Qlobber.prototype._match2 = function (v, topic)
Qlobber.prototype._match2 = function (v, topic, ctx)
{
var vals = this._match(
{
source: v
}, 0, topic.split(this._separator), this._trie);
}, 0, topic.split(this._separator), this._trie, ctx);

return vals.source || vals;
};
Expand Down Expand Up @@ -453,9 +453,9 @@ Match a topic.
@param {String} topic The topic to match against.
@return {Array} List of values that matched the topic. This may contain duplicates.
*/
Qlobber.prototype.match = function (topic)
Qlobber.prototype.match = function (topic, ctx)
{
return this._match2([], topic);
return this._match2([], topic, ctx);
};

/**
Expand Down Expand Up @@ -567,9 +567,9 @@ Match a topic.
@param {String} topic The topic to match against.
@return {Set} [ES6 Set](http://www.ecma-international.org/ecma-262/6.0/#sec-set-objects) of values that matched the topic.
*/
QlobberDedup.prototype.match = function (topic)
QlobberDedup.prototype.match = function (topic, ctx)
{
return this._match2(new Set(), topic);
return this._match2(new Set(), topic, ctx);
};

/**
Expand Down Expand Up @@ -629,9 +629,9 @@ calls [`test`](#qlobberprototypetesttopic-val) (with value `undefined`).
@param {String} topic The topic to match against.
@return {Boolean} Whether the `QlobberTrue` instance matches the topic.
*/
QlobberTrue.prototype.match = function (topic)
QlobberTrue.prototype.match = function (topic, ctx)
{
return this.test(topic);
return this.test(topic, ctx);
};

exports.Qlobber = Qlobber;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "qlobber",
"description": "Node.js globbing for amqp-like topics",
"version": "1.1.0",
"version": "1.2.0",
"homepage": "https://github.com/davedoesdev/qlobber",
"author": {
"name": "David Halls",
Expand Down
9 changes: 6 additions & 3 deletions test/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
var util = require('util'),
expect = require('chai').expect,
qlobber = require('..'),
Qlobber = qlobber.Qlobber;
Qlobber = qlobber.Qlobber,
ctx = 'some context';

function QosQlobber(options)
{
Expand All @@ -23,8 +24,10 @@ QosQlobber.prototype._add_value = function (vals, val)
vals.set(val.clientId, val);
};

QosQlobber.prototype._add_values = function (dest, origin)
QosQlobber.prototype._add_values = function (dest, origin, context)
{
expect(context).to.equal(ctx);

origin.forEach(function (val, key)
{
dest.set(key, val);
Expand All @@ -49,7 +52,7 @@ QosQlobber.prototype.test_values = function (vals, val)

QosQlobber.prototype.match = function (topic)
{
return this._match2(new Map(), topic);
return this._match2(new Map(), topic, ctx);
};

describe('qlobber-custom', function ()
Expand Down

0 comments on commit 2e84270

Please sign in to comment.