Quartz::Verifiers::RuntimeChecker
A simple base class that can be used along with Verifiable#check_with
class MyModel
include Verifiable
check_with MyVerifier
end
class MyVerifier < RuntimeChecker
def check(model)
if some_complex_logic
model.errors.add(:base, "This model is invalid")
end
end
private def some_complex_logic
# ...
end
end
Any class that inherits from RuntimeChecker must implement a
method called #check which accepts a model.
class MyModel
include Verifiable
check_with MyVerifier
end
class MyVerifier < RuntimeChecker
def check(model)
model # => The model instance being validated
end
end
To cause a verification error, you must add to the model's errors directly from within the verifiers message.
class MyVerifier < RuntimeChecker
def check(model)
model.errors.add :attr1, "This is some custom error message"
model.errors.add :attr2, "This is some complex validation"
# etc...
end
end
Note that the verifier is initialized only once for the whole application life cycle, and not on each verification run.
Constructors
new
SourceInstance methods
check(model) : Bool
Override this method in subclasses with verification logic, adding errors to the models errors array where necessary.
contexts
Sourcestrict?
Whether this verifier will cause a StrictVerificationFailed error to
be raised when #check returns false.