Class: EasyJSONMatcher::Validator
- Inherits:
-
Object
- Object
- EasyJSONMatcher::Validator
- Defined in:
- lib/easy_json_matcher/validator.rb
Instance Attribute Summary collapse
-
#coercer ⇒ Object
readonly
Returns the value of attribute coercer.
-
#key ⇒ Object
Returns the value of attribute key.
-
#validation_chain ⇒ Object
readonly
Returns the value of attribute validation_chain.
Instance Method Summary collapse
-
#_post_initialise(options) ⇒ Object
Hook.
-
#initialize(validate_with:, **args) ⇒ Validator
constructor
A new instance of Validator.
- #valid?(candidate:) ⇒ Boolean
- #validate(candidate:) ⇒ Object
Constructor Details
#initialize(validate_with:, **args) ⇒ Validator
Returns a new instance of Validator.
8 9 10 11 |
# File 'lib/easy_json_matcher/validator.rb', line 8 def initialize(validate_with:, **args) super(**args) @validation_chain = validate_with end |
Instance Attribute Details
#coercer ⇒ Object (readonly)
Returns the value of attribute coercer.
5 6 7 |
# File 'lib/easy_json_matcher/validator.rb', line 5 def coercer @coercer end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/easy_json_matcher/validator.rb', line 6 def key @key end |
#validation_chain ⇒ Object (readonly)
Returns the value of attribute validation_chain.
5 6 7 |
# File 'lib/easy_json_matcher/validator.rb', line 5 def validation_chain @validation_chain end |
Instance Method Details
#_post_initialise(options) ⇒ Object
Hook. Allows further setup to be carried out by subclasses
14 |
# File 'lib/easy_json_matcher/validator.rb', line 14 def _post_initialise(); end |
#valid?(candidate:) ⇒ Boolean
16 17 18 19 |
# File 'lib/easy_json_matcher/validator.rb', line 16 def valid?(candidate:) errors = validate(candidate: candidate) errors.empty? end |
#validate(candidate:) ⇒ Object
21 22 23 24 |
# File 'lib/easy_json_matcher/validator.rb', line 21 def validate(candidate:) candidate = coercer.coerce(json: candidate) validation_chain.call(value: candidate) end |