Quartz::Verifiable
Provides a runtime verification framework for your models.
Example:
class WeightModel
include Quartz::Verifiable
property weight : Float64 = 0.0 # in kg
check :weight, numericality: {greater_than: 40, lesser_than: 160}
end
model = WeightModel.new
model.weight = 75.0
model.valid? # => true
model.invalid? # => false
model.weight = 200.0
model.valid? # => false
model.invalid? # => true
model.errors.messages # => { :weight => ["must be lesser than 160"] }
Instance methods
errors
Returns the VerificationErrors object that holds all information about
attribute error messages.
Performs the opposite of #valid?. Returns true if errors were added,
false otherwise.
Usage:
class MyModel
include Quartz::Verifiable
property :phase : String?
check :phase, presence: true
end
model = MyModel.new
model.phase = ""
model.invalid? # => true
model.phase = "idle"
model.invalid? # => false
Context can optionally be supplied to define which verifiers to test against (the context is defined on the verifiers using on: option).