Skip to content
Browse files

Add support for multi-key/value context node lookups

Empty lookups return false, only if each key/value pair match does it
return true.
  • Loading branch information...
1 parent e38f66c commit ceedd3e4e33c902902746d646755fb7e56c41d6f @bruth bruth committed
Showing with 11 additions and 6 deletions.
  1. +11 −6 coffee/cilantro/models/context.coffee
View
17 coffee/cilantro/models/context.coffee
@@ -5,14 +5,19 @@ define [
class ContextNodeError extends Error
- queryAttrs = (attrs, query, options) ->
+ queryAttrs = (attrs={}, query={}, options) ->
if attrs instanceof ContextNodeModel
attrs = attrs.attributes
- if query.concept? and attrs.concept is query.concept
- return true
- if query.field? and attrs.field is query.field
- return true
- return false
+
+ # No empty queries
+ if c._.isEmpty(query) then return false
+
+ # Check against each key in the query for a match on attrs
+ for key, value of query
+ if attrs[key] isnt value
+ return false
+
+ return true
# Represents a single node within a ContextModel tree. Non-branch nodes

0 comments on commit ceedd3e

Please sign in to comment.
Something went wrong with that request. Please try again.