openstreetmap-website/app/validators/width_validator.rb

11 lines
269 B
Ruby

class WidthValidator < ActiveModel::Validations::LengthValidator
module WidthAsLength
def length
Unicode::DisplayWidth.of(to_s)
end
end
def validate_each(record, attribute, value)
super(record, attribute, value.extend(WidthAsLength))
end
end