Class: Validate::Assertions::Assertion
- Inherits:
-
Object
- Object
- Validate::Assertions::Assertion
- Defined in:
- lib/validate/assertions.rb
Instance Method Summary collapse
- #assert(value, error_class: Error::ArgumentError, message: 'invalid value') ⇒ Object
-
#initialize(validation_context) ⇒ Assertion
constructor
A new instance of Assertion.
Constructor Details
#initialize(validation_context) ⇒ Assertion
Returns a new instance of Assertion.
13 14 15 |
# File 'lib/validate/assertions.rb', line 13 def initialize(validation_context) @constraints = validation_context end |
Instance Method Details
#assert(value, error_class: Error::ArgumentError, message: 'invalid value') ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/validate/assertions.rb', line 17 def assert(value, error_class: Error::ArgumentError, message: 'invalid value') ctx = Constraints::ValidationContext.root(value) @constraints.evaluate(ctx) return value unless ctx.has_violations? raise error_class, , cause: ctx.to_err end |