Skip to content

Commit

Permalink
Add error messages and optimistic / pessimistic failures
Browse files Browse the repository at this point in the history
  • Loading branch information
baweaver committed Feb 18, 2019
1 parent 60362f1 commit c108f53
Show file tree
Hide file tree
Showing 5 changed files with 480 additions and 8 deletions.
295 changes: 295 additions & 0 deletions docs/Qo/Exceptions/ExhaustiveMatchNotMet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Exception: Qo::Exceptions::ExhaustiveMatchNotMet

&mdash; Documentation by YARD 0.9.12

</title>

<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />

<link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
pathId = "Qo::Exceptions::ExhaustiveMatchNotMet";
relpath = '../../';
</script>


<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>

<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>


</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../../class_list.html?1"></iframe>
<div id="resizer"></div>
</div>

<div id="main" tabindex="-1">
<div id="header">
<div id="menu">

<a href="../../_index.html">Index (E)</a> &raquo;
<span class='title'><span class='object_link'><a href="../../Qo.html" title="Qo (module)">Qo</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Exceptions.html" title="Qo::Exceptions (module)">Exceptions</a></span></span>
&raquo;
<span class="title">ExhaustiveMatchNotMet</span>

</div>

<div id="search">

<a class="full_list_link" id="class_list_link"
href="../../class_list.html">

<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>

</div>
<div class="clear"></div>
</div>

<div id="content"><h1>Exception: Qo::Exceptions::ExhaustiveMatchNotMet



</h1>
<div class="box_info">

<dl>
<dt>Inherits:</dt>
<dd>
<span class="inheritName">StandardError</span>

<ul class="fullTree">
<li>Object</li>

<li class="next">StandardError</li>

<li class="next">Qo::Exceptions::ExhaustiveMatchNotMet</li>

</ul>
<a href="#" class="inheritanceTree">show all</a>

</dd>
</dl>











<dl>
<dt>Defined in:</dt>
<dd>lib/qo/exceptions.rb</dd>
</dl>

</div>

<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Error for not all possible cases being handled. This is optimistic as currently
it will only catch when an actual failure to handle a case is present. This
should be patched in later versions</p>


</div>
</div>
<div class="tags">

<p class="tag_title">Author:</p>
<ul class="author">

<li>





<div class='inline'><p>baweaver</p>
</div>

</li>

</ul>
<p class="tag_title">Since:</p>
<ul class="since">

<li>





<div class='inline'><p>0.99.1</p>
</div>

</li>

</ul>

</div>
<h2>Constant Summary</h2>
<dl class="constants">

<dt id="MESSAGE-constant" class="">MESSAGE =
<div class="docstring">
<div class="discussion">


</div>
</div>
<div class="tags">

<p class="tag_title">Since:</p>
<ul class="since">

<li>





<div class='inline'><p>0.99.1</p>
</div>

</li>

</ul>

</div>
</dt>
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Exhaustive match required - pattern does not satisfy all possible conditions</span><span class='tstring_end'>&#39;</span></span></pre></dd>

</dl>








<h2>
Instance Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>

<ul class="summary">

<li class="public ">
<span class="summary_signature">

<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong> &#x21d2; ExhaustiveMatchNotMet </a>



</span>


<span class="note title constructor">constructor</span>








<span class="summary_desc"><div class='inline'><p>A new instance of ExhaustiveMatchNotMet.</p>
</div></span>

</li>


</ul>



<div id="constructor_details" class="method_details_list">
<h2>Constructor Details</h2>

<div class="method_details first">
<h3 class="signature first" id="initialize-instance_method">

#<strong>initialize</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Qo::Exceptions::ExhaustiveMatchNotMet (class)">ExhaustiveMatchNotMet</a></span></tt>





</h3><div class="docstring">
<div class="discussion">
<p>Returns a new instance of ExhaustiveMatchNotMet</p>


</div>
</div>
<div class="tags">

<p class="tag_title">Since:</p>
<ul class="since">

<li>





<div class='inline'><p>0.99.1</p>
</div>

</li>

</ul>

</div><table class="source_code">
<tr>
<td>
<pre class="lines">


20
21
22</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/qo/exceptions.rb', line 20</span>

<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
<span class='kw'>super</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="#MESSAGE-constant" title="Qo::Exceptions::ExhaustiveMatchNotMet::MESSAGE (constant)">MESSAGE</a></span></span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>

</div>


</div>

<div id="footer">
Generated on Mon Feb 18 02:14:19 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.12 (ruby-2.6.1).
</div>

</div>
</body>
</html>
16 changes: 15 additions & 1 deletion lib/qo/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,25 @@ module Exceptions
# @author baweaver
# @since 0.99.1
class ExhaustiveMatchNotMet < StandardError
MESSAGE = 'Exhaustive match required - pattern does not satisfy all possible conditions'
MESSAGE = 'Exhaustive match required: pattern does not satisfy all possible conditions'

def initialize
super(MESSAGE)
end
end

# Not all branches were definied in an exhaustive matcher
#
# @author baweaver
# @since 0.99.1
class ExhaustiveMatchMissingBranches < StandardError
def initialize(expected_branches:, given_branches:)
super <<~MESSAGE
Exhaustive match required: pattern does not specify all branches.
Expected Branches: #{expected_branches.join(', ')}
Given Branches: #{given_branches.join(', ')}
MESSAGE
end
end
end
end
11 changes: 11 additions & 0 deletions lib/qo/pattern_matchers/branching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def self.included(base)
# @author baweaver
# @since 1.0.0
module ClassMethods
attr_reader :available_branches

# Registers a branch to a pattern matcher.
#
# This defines a method on the pattern matcher matching the `name` of
Expand All @@ -29,10 +31,19 @@ module ClassMethods
# When called, this will either ammend a matcher to the list of matchers
# or set a default matcher if the branch happens to be a default.
#
# It also adds the branch to a registry of branches for later use in
# error handling or other such potential requirements.
#
# @param branch [Branch]
# Branch object to register with a pattern matcher
def register_branch(branch)
@available_branches ||= {}
@available_branches[branch.name] = branch

define_method(branch.name) do |*conditions, **keyword_conditions, &function|
@provided_matchers ||= []
@provided_matchers.push(branch.name)

qo_matcher = Qo::Matchers::Matcher.new('and', conditions, keyword_conditions)

branch_matcher = branch.create_matcher(
Expand Down
Loading

0 comments on commit c108f53

Please sign in to comment.