Mailspring/docs/Matcher.html
2015-10-03 12:57:50 -07:00

39 lines
1.3 KiB
HTML

---
layout: docs
title: Matcher
edit_url: "https://github.com/nylas/N1/blob/master/src/flux/attributes/matcher.coffee"
---
<h2>Summary</h2>
<div class="markdown-from-sourecode">
<p><p>The Matcher class encapsulates a particular comparison clause on an <a href='attribute.html'>Attribute</a>.
Matchers can evaluate whether or not an object matches them, and also compose
SQL clauses for the DatabaseStore. Each matcher has a reference to a model
attribute, a comparator and a value.</p>
<pre><code class="lang-coffee">
<span class="hljs-preprocessor"># Retrieving Matchers</span>
isUnread = Thread.attributes.unread.equal(<span class="hljs-literal">true</span>)
hasLabel = Thread.attributes.lables.contains(<span class="hljs-string">'label-id-123'</span>)
<span class="hljs-preprocessor"># Using Matchers in Database Queries</span>
DatabaseStore.findAll(Thread).where(isUnread)...
<span class="hljs-preprocessor"># Using Matchers to test Models</span>
threadA = <span class="hljs-keyword">new</span> Thread(unread: <span class="hljs-literal">true</span>)
threadB = <span class="hljs-keyword">new</span> Thread(unread: <span class="hljs-literal">false</span>)
isUnread.evaluate(threadA)
<span class="hljs-preprocessor"># =&gt; true</span>
isUnread.evaluate(threadB)
<span class="hljs-preprocessor"># =&gt; false</span>
</code></pre>
</p>
</div>
<ul>
</ul>