Module: Qo::PublicApi
Overview
The Public API consists of methods that should be openly accessible to the top level Qo namespace, and should not change. It should be used as the subject of Acceptance level tests for the library and should not have its externally facing methods renamed or moved under pain of a look of profound disappointment from the creator.
Instance Method Summary collapse
-
#and(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
(also: #[])
Creates an
and
type query matcher. -
#match(*args) ⇒ Qo::PatternMatch | Any
"Curried" function that waits for a target, or evaluates immediately if given one.
-
#matcher(*array_matchers, **keyword_matchers, &fn) ⇒ Proc[Any]
(also: #m)
Creates a Guard Block matcher.
-
#not(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
Creates a
not
type query matcher. -
#or(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
Creates an
or
type query matcher.
Instance Method Details
#and(*array_matchers, **keyword_matchers) ⇒ Proc[Any] Also known as: []
Creates an and
type query matcher. All conditions in this type of matcher
must pass to be considered a "match". It will short-circuit in the case of
a false match.
23 24 25 |
# File 'lib/qo/public_api.rb', line 23 def and(*array_matchers, **keyword_matchers) create_matcher('and', *array_matchers, **keyword_matchers) end |
#match(*args) ⇒ Qo::PatternMatch | Any
"Curried" function that waits for a target, or evaluates immediately if given one.
A PatternMatch will try and run all GuardBlock matchers in sequence until it finds one that "matches". Once found, it will pass the target into the associated matcher's block function.
90 91 92 93 94 95 96 97 |
# File 'lib/qo/public_api.rb', line 90 def match(*args) if args.first.is_a?(Qo::Matchers::GuardBlockMatcher) Qo::Matchers::PatternMatch.new(*args) else match_target, *qo_matchers = args Qo::Matchers::PatternMatch.new(*qo_matchers).call(match_target) end end |
#matcher(*array_matchers, **keyword_matchers, &fn) ⇒ Proc[Any] Also known as: m
Creates a Guard Block matcher.
A guard block matcher is used to guard a function from running unless
the left-hand matcher passes. Once called with a value, it will either
return [false, false]
or [true, Any]
.
This wrapping is done to preserve intended false or nil responses, and is unwrapped with match below.
71 72 73 |
# File 'lib/qo/public_api.rb', line 71 def matcher(*array_matchers, **keyword_matchers, &fn) Qo::Matchers::GuardBlockMatcher.new(*array_matchers, **keyword_matchers, &fn) end |
#not(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
Creates a not
type query matcher. No conditions in this type of matcher
should pass to be considered a "match". It will short-circuit in the case of
a true match.
52 53 54 |
# File 'lib/qo/public_api.rb', line 52 def not(*array_matchers, **keyword_matchers) create_matcher('not', *array_matchers, **keyword_matchers) end |
#or(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
Creates an or
type query matcher. Any conditions in this type of matcher
must pass to be considered a "match". It will short-circuit in the case of
a true match.
39 40 41 |
# File 'lib/qo/public_api.rb', line 39 def or(*array_matchers, **keyword_matchers) create_matcher('or', *array_matchers, **keyword_matchers) end |