trabajo-afectivo/app/models/object_manager/attribute/validation/min_max.rb
2022-01-01 14:38:12 +01:00

32 lines
849 B
Ruby

# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class ObjectManager::Attribute::Validation::MinMax < ObjectManager::Attribute::Validation::Backend
def validate
return if value.blank?
return if irrelevant_attribute?
validate_min
validate_max
end
private
def irrelevant_attribute?
attribute.data_type != 'integer'.freeze
end
def validate_min
return if !attribute.data_option[:min]
return if value >= attribute.data_option[:min]
invalid_because_attribute("is smaller than the allowed minimum value of #{attribute.data_option[:min]}")
end
def validate_max
return if !attribute.data_option[:max]
return if value <= attribute.data_option[:max]
invalid_because_attribute("is larger than the allowed maximum value of #{attribute.data_option[:max]}")
end
end