Class: Latin1Validator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/latin1_validator.rb

Overview

NPG expressed concerns that switching the Sequencescape to Utf8 would result in an increase in characters which could not be processed by their pipelines. This validator checks that the characters can be represented in latin1, ensuring that we don't make the problem worse in the short term. This will likely be replaced by more specific validations as we become aware of exactly what is supported. It has been applied to the key fields that get added to headers and the like.

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/validators/latin1_validator.rb', line 11

def validate_each(record, attribute, value)
  return true if value.blank?

  value.encode('cp1252')
  return true if value.encode('cp1252').valid_encoding?
rescue Encoding::UndefinedConversionError => e
  record.errors[attribute] <<
    (
      options[:message] ||
        "contains unsupported characters (non-latin characters), remove or replace them: #{e.error_char}"
    )
end