Class: EacRailsUtils::YamlValidator

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

Constant Summary collapse

DEFAULT_INVALID_YAML_MESSAGE =
'is not a valid YAML'
DEFAULT_TO_S_UNAVAILABLE_MESSAGE =
'should respond to .to_s'
DEFAULT_NOT_A_STRING_MESSAGE =
'.to_s do not returned a String'

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



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

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

  string_value = stringfy_value(value)
  return if string_value.nil?

  return if ::EacRubyUtils::Yaml.yaml?(string_value)

  record.errors[attribute] << (options[:message] || DEFAULT_INVALID_YAML_MESSAGE)
end