class DeviceContract < Dry::Validation::Contract
def initialize
super
end
params do
required(:screen_size).filled(:int?)
end
rule(:screen_size) do
key.failure('invalid screen size') if value < 1
end
end
class PcContract < DeviceContract
def initialize
super
end
params do
required(:keyboard).filled(:str?)
end
rule(:keyboard_type) do
key.failure('invalid keyboard type') if KEYBOARD_TYPES.exclude?(value)
end
end
I call the PcContract and it seems to work (it validates keyboard_type but screen_size as well). Further, my experiments shown that it is seems to be possible to overwrite only some of the params defined in the base class and still use the rest.
Is there any contraindication against the above described inheritance? Am I missing something?