Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 01, 2013
Chakrit Wichian Add .has method for checking membership. 976eb74
Chakrit Wichian Add test for .members 05aa683
@tblobaum Merge pull request #2 from chakrit/feature/member.has
Add .has method for checking membership.
70e5011
Showing with 38 additions and 2 deletions.
  1. +10 −1 README.md
  2. +11 −0 index.js
  3. +17 −1 test/groups-test.js
View
11 README.md
@@ -67,6 +67,15 @@ Node('me').membership.add('user', function (error) {
})
```
+## .{members,membership}.has(node, function (error, hasNode) { ... })
+checks wether not this instance has an edge to `node`
+
+``` js
+Node('user').members.has('me', function (error, hasUser) {
+ // hasUser == true || hasUser == false
+})
+```
+
## .{members,membership}.all(function (error, nodes) { ... })
return a list of nodes
@@ -345,4 +354,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
11 index.js
@@ -156,6 +156,17 @@ Edge.prototype.add = function (arr, cb) {
}
/**
+ * Checks if parent `node` instance has an edge to `member`
+ *
+ * @param {String} member
+ * @param {Function} cb
+ */
+
+Edge.prototype.has = function (member, cb) {
+ db.sismember(this.innerkey, member, cb)
+}
+
+/**
* Delete edges to `arr` for the parent `node` instance
*
* @param {String || Array} arr
View
18 test/groups-test.js
@@ -13,18 +13,26 @@ var Tom = group('tom')
test('test all the things', function (t) {
- t.plan(96)
+ t.plan(100)
Tom.membership.add('anonymous', function (error, result) {
t.deepEqual(error, null, 'error should be null')
t.deepEqual(result, [ 1, 1 ], 'result should be the same')
})
+ Tom.membership.has('admin', function (error, result) {
+ t.notOk(result, 'result should be falsy')
+ })
+
Tom.membership.add('admin', function (error, result) {
t.deepEqual(error, null, 'error should be null')
t.deepEqual(result, [ 1, 1 ], 'result should be the same')
})
+ Tom.membership.has('admin', function (error, result) {
+ t.ok(result, 'result should be truthy')
+ });
+
Tom.membership.add('one', function (error, result) {
t.deepEqual(error, null, 'error should be null')
t.deepEqual(result, [ 1, 1 ], 'result should be the same')
@@ -155,6 +163,10 @@ test('test all the things', function (t) {
t.deepEqual(result.sort(), [ 'javascript', 'nodejs', 'otherGroup', 'anonymous', 'admin', 'one', 'two' ].sort(), 'result should be the same')
})
+ nodejs.members.has(javascript, function (error, result) {
+ t.notOk(result, 'result should be falsy')
+ })
+
nodejs.members.add(javascript, function (error, result) {
t.deepEqual(error, null, 'error should be null')
t.deepEqual(result, [ 1, 1 ], 'result should be the same')
@@ -164,6 +176,10 @@ test('test all the things', function (t) {
})
})
+ nodejs.members.has(javascript, function (error, result) {
+ t.ok(result, 'result should be truthy')
+ })
+
javascript.members.all(function (error, result) {
t.deepEqual(error, null, 'error should be null')
t.deepEqual(result.sort(), [ 'tom', 'bob', 'bill' ].sort(), 'result should be the same')

No commit comments for this range

Something went wrong with that request. Please try again.