Class: PropertyValueValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/property_value_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/models/property_value_validator.rb', line 3

def validate(record)
  return true unless record.new_value
  template, rxp = record.template.split('+')
  rxp = template unless rxp
  if validation = Validations[rxp]
    if record.new_value ~! validation
      record.errors[:base] << I18n.t('validation.format')
      return false
    end
  end
  true
end