Module: Ward::Matchers
- Defined in:
- lib/ward/matchers.rb,
lib/ward/matchers/has.rb,
lib/ward/matchers/nil.rb,
lib/ward/matchers/match.rb,
lib/ward/matchers/include.rb,
lib/ward/matchers/matcher.rb,
lib/ward/matchers/present.rb,
lib/ward/matchers/satisfy.rb,
lib/ward/matchers/close_to.rb,
lib/ward/matchers/equal_to.rb,
lib/ward/matchers/predicate.rb,
lib/ward/matchers/acceptance.rb
Overview
Matchers are used to determine whether a particular value is valid.
Any class instance can be a validator so long as it responds to #matches?; the #matches? method should take at least one argument which will be the value of the object being validated. The matcher should then return a true-like value if the match is successful or either nil, false, or an array whose first member is false, if the match was not successful.
In the event that your matcher returns an array, the second member will be used as the error message.
Defined Under Namespace
Classes: Acceptance, CloseTo, EqualTo, Has, Include, Match, Matcher, Nil, Predicate, Present, Satisfy
Class Method Summary collapse
-
.matchers ⇒ Hash{Symbol => Ward::Matchers::Matcher}
Returns the registered matchers.
-
.register(slug, matcher) ⇒ Object
Registers a matcher and it’s slug.
Class Method Details
.matchers ⇒ Hash{Symbol => Ward::Matchers::Matcher}
Returns the registered matchers.
76 77 78 |
# File 'lib/ward/matchers.rb', line 76 def self.matchers @matchers ||= {} end |
.register(slug, matcher) ⇒ Object
Registers a matcher and it’s slug.
A matcher can be registered with as many slugs as desired.
68 69 70 |
# File 'lib/ward/matchers.rb', line 68 def self.register(slug, matcher) matchers[slug.to_sym] = matcher end |