I have a Contract that has the following setup:
class MyContract < Dry::Validation::Contract
option :some_activerecord
params do
optional(:amount).maybe(:number?, gt?: 0)
end
rule do
binding.pry
end
end
Is there a way to only have the optional param
validation to run if a certain property in some_activerecord
model is equal to a value without having to create an actual rule? Trying to keep the params as short as possible, and wondering if this is possible?
I’ve tried:
optional(:amount).maybe(:number?, gt?: 0) { some_activerecord.value == 0 }
But this failed with undefined local variable or method
.
Thanks!