doc/file.README.html in schemacop-2.3.1 vs doc/file.README.html in schemacop-2.3.2
- old
+ new
@@ -254,12 +254,12 @@
Just like <code>if</code>, <code>check</code> takes a proc or lambda as a value, but it runs <em>after</em>
the type checking, meaning that it only gets executed if the data has the right
type and the proc in <code>if</code> (if any) has returned true.</p>
<p>The proc passed to the <code>check</code> option is given the data being analyzed. It is to
-return true if the data passes the custom check. If it returns false, Schemacop
-considers the data to be invalid.</p>
+return true if the data passes the custom check. If it returns false or an error
+message as a string, Schemacop considers the data to be invalid.</p>
<p>The following example illustrates the use of the option <code>check</code>: Consider a
scenario in which you want the following rule set:</p>
<ul>
@@ -276,10 +276,19 @@
</code></pre>
<p>The above Type Line has type <code>:string</code> and two options (<code>min</code> and <code>check</code>). The
option <code>min</code> is supported by the <code>:string</code> validator (covered later).</p>
+<p>You can also specify a custom error message by returning a string:</p>
+
+<pre class="code ruby"><code class="ruby"><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
+ <span class='id identifier rubyid_type'>type</span> <span class='symbol'>:integer</span><span class='comma'>,</span> <span class='label'>check:</span> <span class='id identifier rubyid_proc'>proc</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_i'>i</span><span class='op'>|</span> <span class='id identifier rubyid_i'>i</span><span class='period'>.</span><span class='id identifier rubyid_even?'>even?</span> <span class='op'>?</span> <span class='kw'>true</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Custom error</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span>
+<span class='kw'>end</span>
+</code></pre>
+
+<p>This will include <code>Custom error</code> in the validation error message.</p>
+
<h3>Field Line</h3>
<p>Inside a Type Line of type <code>:hash</code>, you may specify an arbitrary number of field
lines (one for each key-value pair you want to be in the hash).</p>
@@ -624,10 +633,10 @@
<p>Copyright (c) 2019 Sitrox. See <code>LICENSE</code> for further details.</p>
</div></div>
<div id="footer">
- Generated on Mon Aug 19 12:55:07 2019 by
+ Generated on Thu Sep 26 13:19:46 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.20 (ruby-2.6.2).
</div>
</div>
\ No newline at end of file