jmettraux/rufus-decision — pull request #9 by lastobelus (2013-05-22 20:47:57+00:00)
Title: Matchers need to be able to short-circuit evaluation

If a matcher does not match a cell, but is the correct matcher that COULD match the cell, it needs to be able to tell rufus-decision this so that rufus-decision does not run subsequent matchers.

There are three ways I see to do this:

1. give Rufus::Decision::Matcher a should_match? method. The evaluation loop would call this on the matcher first. It should return a 3-state boolean (true, false or nil):
* if true --> run matcher.matches? and don't run any other matchers regardless of result
* if false -> don't run matcher.matches? and continue running other matchers
* if nil -> run matcher.matches? and continue running other matches if it returns false
This option means we would not have to touch the current matchers.

2. The second way would be to use similar logic but have matches? return the 3-state boolean. This however means that all matchers have to be aware of the contract.

3. The third way is to have matches? raise an exception in order to short circuit further matching. This is good architecturally, but expensive.

I prefer 1).

Let me know if you see a good reason to prefer one of the other ways, otherwise I will go ahead and implement 1) and submit as a pull request.